package com.bbcare.exportExcel.plat.service.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bbcare.comm.AppException;
import com.bbcare.comm.Constants;
import com.bbcare.comm.DateUtil;
import com.bbcare.comm.ErrorCode;
import com.bbcare.comm.OSSClientUtil;
import com.bbcare.comm.SeqUtil;
import com.bbcare.comm.ToolUtils;
import com.bbcare.exportExcel.plat.entity.OperationNote;
import com.bbcare.exportExcel.plat.service.IUploadExcelService;
import com.bbcare.exportExcel.plat.store.ibatis.IUploadExcelDAO;
import com.bbcare.exportExcel.plat.utils.EvaluateUtils;
import com.bbcare.followup.plat.entity.FuAssessMentPosition;
import com.bbcare.followup.plat.entity.PatientContentData;
import com.bbcare.followup.plat.entity.PatientTask;
import com.bbcare.followup.plat.service.IPatientService;
import com.bbcare.followup.plat.store.ibatis.IConfCacheDAO;
import com.bbcare.followup.plat.store.ibatis.IFollowEvaluationDAO;
import com.bbcare.followup.plat.store.ibatis.IPatientTaskContentDAO;
import com.bbcare.followup.plat.store.ibatis.IPatientTaskDAO;

@Service
public class UploadExcelService implements IUploadExcelService {
	static Logger logger = Logger.getLogger(UploadExcelService.class);
	//private static Connection connection = InsertDemoData.getConnection();
	@Autowired
	IFollowEvaluationDAO followEvaluationDao;

	@Autowired
    private IPatientService patientSerivce;

	@Autowired
    private IPatientTaskDAO patientTaskDao;

	@Autowired
	private IUploadExcelDAO iUploadExcelDAO;

	@Autowired
	public IConfCacheDAO confCacheDAO;

	@Autowired
    private IPatientTaskContentDAO PatientContentDao;
	//母乳喂养
	public void  queryBreastFeed(Map<String,Object> map) throws Exception{
		Connection connection = null;
    	String url = "jdbc:mysql://rdsap8226j2iuruyoaamgpublic.mysql.rds.aliyuncs.com:3306/bbcare_cloud?createDatabaseIfNotExist=true&amp;amp;useUnicode=true&amp;amp;characterEncoding=utf8mb4&amp;amp;zeroDateTimeBehavior=convertToNull&amp;amp;transformedBitIsBoolean=true";
    	String username = "yunyin";
    	String password = "cl123456";
    	try {
			connection = DriverManager.getConnection(url, username, password);
		} catch (SQLException e) {

			e.printStackTrace();
		}

    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");//格式化为年月
    	//开始和结束时间
		String beginTime = (String) map.get("beginTime");
		String endTime = (String) map.get("endTime");
		String sqlAdd = "";
		Map<String,Object> MapIn =  new HashMap<String,Object>(map);
		//计算两个时间中相差的月份
		if(!StringUtils.isBlank(beginTime)) {
			List <String> listMouth = DateUtil.daysBetweenmouth(beginTime,endTime);
			for(int i=0;i<listMouth.size();i++) {
				if(!StringUtils.isBlank(listMouth.get(i))) {
					sqlAdd = " where m.t3createTime>='"+listMouth.get(i)+"-01 00:00:00"+"' and m.t3createTime<='"+listMouth.get(i)+"-31 23:59:59"+"'";
				}
				MapIn.put("mouth", listMouth.get(i));
				List<Map<String, Object>> list = iUploadExcelDAO.selectOperationNote(MapIn);
				if(list!=null&&list.size()>0&&!listMouth.get(i).equals(sdf.format(new Date()))) {
					logger.info("已有导出数据!");
				}else {
					querybreastfeed(connection,sqlAdd,listMouth.get(i),sdf.format(new Date()),map);
				}
			}
		}else {
			querybreastfeed(connection,sqlAdd,"",sdf.format(new Date()),map);
		}


	}

	public void querybreastfeed(Connection connection,String sqlAdd,String time,String nowDate,Map<String,Object> map) throws Exception {
		//按月导出数据，当前月份每次都需要重新生成，并且不需要上传，和将记录入表
    	Workbook workbook = new SXSSFWorkbook(100);
 		Sheet sheet = workbook.createSheet("资料");
 		Sheet sheet1 = workbook.createSheet("孕早");
 		Sheet sheet2 = workbook.createSheet("孕中");
 		Sheet sheet3 = workbook.createSheet("孕晚");
 		Sheet sheet4 = workbook.createSheet("分娩时");
 		Sheet sheet5 = workbook.createSheet("产褥期");
 		//基本资料
 		getsumziliao(map,sheet,connection);
 		//孕早
 		getsumyunzao(map,sheet1,connection);
 		//孕中
 		getsumyunzhong(map,sheet2,connection);
 		//孕晚
 		getsumyunwan(map,sheet3,connection);
 		//分娩时
 		getsumfenmian(map,sheet4,connection);
 		//产褥期
 		getsumychanru(map,sheet5,connection);
        String fileName = "C:\\Users\\Administrator\\Desktop\\upload\\母乳喂养"+time+".xls";
		OutputStream outputStream = new FileOutputStream(new File(fileName));
		workbook.write(outputStream);
		workbook.close();
		OperationNote OperationNote = new OperationNote();
		String id = SeqUtil.getSeqNo(Constants.SEQ_NO_FOR_SHUJUDAOCHU);
		OperationNote.setId(id);
		OperationNote.setTalentId((String)map.get("talentId"));
		OperationNote.setDeptId((String)map.get("deptId"));
		OperationNote.setDoctor_id((String)map.get("authorId"));
		OperationNote.setDoctor_name((String)map.get("authorName"));
		OperationNote.setBak1("");
		OperationNote.setBak2("");
		OperationNote.setBak3("");
		OperationNote.setMouth(time);
		OperationNote.setProject_id((String)map.get("projectId"));
		OperationNote.setProject_name((String)map.get("projectName"));
		OperationNote.setQueueId((String)map.get("queueId"));
		OperationNote.setUpdate_time((String)map.get("updateTime"));
		OperationNote.setCreate_time((String)map.get("createTime"));
		if(!StringUtils.isBlank(time) && time.equals(nowDate)) {
			logger.info("当前月份先更新，没有在上传！");
			uploadFile(fileName);
			Map<String,Object> map1 = new HashMap<String,Object>();
			map1.put("projectId", (String)map.get("projectId"));
			map1.put("projectName", (String)map.get("projectName"));
			map1.put("talentId", (String)map.get("talentId"));
			map1.put("mouth", time);
			map1.put("updateTime", (String)map.get("updateTime"));
			int flag = iUploadExcelDAO.updateOperationNote(map1);
			if(flag<=0) {
				Map<String,Object> mapOut = uploadFile(fileName);
				OperationNote.setFile_name((String)mapOut.get("name"));
				OperationNote.setFileurl((String)mapOut.get("url"));
				iUploadExcelDAO.saveOperationNote(OperationNote);
			}
		}else if(!StringUtils.isBlank(time) && !time.equals(nowDate)) {
			Map<String,Object> mapOut = uploadFile(fileName);
			OperationNote.setFile_name((String)mapOut.get("name"));
			OperationNote.setFileurl((String)mapOut.get("url"));
			iUploadExcelDAO.saveOperationNote(OperationNote);
		}
	}

	public static void getsumziliao(Map<String,Object>map,Sheet sheet,Connection connection) throws SQLException {
		//开始和结束时间
				String beginTime = (String) map.get("beginTime");
				String endTime = (String) map.get("endTime");
				//调用存储过程
		        CallableStatement cs = connection.prepareCall("{call getsumziliao(?,?)}");
		        //存储过程传入参数
		        if(StringUtils.isBlank(beginTime)) {
		        	 cs.setString(1, "");
		             cs.setString(2, "");
		        }else {
		        	 beginTime = beginTime+"-01";
		        	 endTime = endTime+"-31";
		        	 cs.setString(1, beginTime);
		             cs.setString(2, endTime);
		        }

		        // ResultSet rs = cs.executeQuery(); //执行查询操作，并获取结果集
		        //执行存储过程
		        cs.execute();
		        // int rowCount = rs.getRow();
		        ResultSet resultSet = cs.getResultSet();
		        /*resultSet.last();
		        int rowCount = resultSet.getRow();
		        resultSet.beforeFirst();*/
		        ResultSetMetaData rsmd = resultSet.getMetaData() ;
		        int  columnCount = rsmd.getColumnCount();
		        int count = 1;
				Row row1 = sheet.createRow(0);
				//Sheet sheet2 = workbook.createSheet("sheet2") ;
		        while(resultSet.next())
		        {
		        	Row row2 = sheet.createRow(count);
		        	for(int i=1;i<=columnCount;i++) {
		        		String lable  = rsmd.getColumnLabel(i);
		            	String value = resultSet.getString(lable);
		        		if(count==1) {
		        			row1.createCell(i).setCellValue(lable);
		        		}
		        		row2.createCell(i).setCellValue(value);
		        	}
		        	count++;
		        }
	}

	public static void getsumyunzao(Map<String,Object>map,Sheet sheet,Connection connection) throws SQLException {
		//开始和结束时间
				String beginTime = (String) map.get("beginTime");
				String endTime = (String) map.get("endTime");
				//调用存储过程
		        CallableStatement cs = connection.prepareCall("{call getsumyunzao(?,?)}");
		        //存储过程传入参数
		        if(StringUtils.isBlank(beginTime)) {
		        	 cs.setString(1, "");
		             cs.setString(2, "");
		        }else {
		        	 beginTime = beginTime+"-01";
		        	 endTime = endTime+"-31";
		        	 cs.setString(1, beginTime);
		             cs.setString(2, endTime);
		        }

		        // ResultSet rs = cs.executeQuery(); //执行查询操作，并获取结果集
		        //执行存储过程
		        cs.execute();
		        // int rowCount = rs.getRow();
		        ResultSet resultSet = cs.getResultSet();
		        /*resultSet.last();
		        int rowCount = resultSet.getRow();
		        resultSet.beforeFirst();*/
		        ResultSetMetaData rsmd = resultSet.getMetaData() ;
		        int  columnCount = rsmd.getColumnCount();
		        int count = 1;
				Row row1 = sheet.createRow(0);
				//Sheet sheet2 = workbook.createSheet("sheet2") ;
		        while(resultSet.next())
		        {
		        	Row row2 = sheet.createRow(count);
		        	for(int i=1;i<=columnCount;i++) {
		        		String lable  = rsmd.getColumnLabel(i);
		            	String value = resultSet.getString(lable);
		        		if(count==1) {
		        			row1.createCell(i).setCellValue(lable);
		        		}
		        		row2.createCell(i).setCellValue(value);
		        	}
		        	count++;
		        }
	}

	public static void getsumyunzhong(Map<String,Object>map,Sheet sheet,Connection connection) throws SQLException {
		//开始和结束时间
				String beginTime = (String) map.get("beginTime");
				String endTime = (String) map.get("endTime");
				//调用存储过程
		        CallableStatement cs = connection.prepareCall("{call getsumyunzhong(?,?)}");
		        //存储过程传入参数
		        if(StringUtils.isBlank(beginTime)) {
		        	 cs.setString(1, "");
		             cs.setString(2, "");
		        }else {
		        	 beginTime = beginTime+"-01";
		        	 endTime = endTime+"-31";
		        	 cs.setString(1, beginTime);
		             cs.setString(2, endTime);
		        }

		        // ResultSet rs = cs.executeQuery(); //执行查询操作，并获取结果集
		        //执行存储过程
		        cs.execute();
		        // int rowCount = rs.getRow();
		        ResultSet resultSet = cs.getResultSet();
		        /*resultSet.last();
		        int rowCount = resultSet.getRow();
		        resultSet.beforeFirst();*/
		        ResultSetMetaData rsmd = resultSet.getMetaData() ;
		        int  columnCount = rsmd.getColumnCount();
		        int count = 1;
				Row row1 = sheet.createRow(0);
				//Sheet sheet2 = workbook.createSheet("sheet2") ;
		        while(resultSet.next())
		        {
		        	Row row2 = sheet.createRow(count);
		        	for(int i=1;i<=columnCount;i++) {
		        		String lable  = rsmd.getColumnLabel(i);
		            	String value = resultSet.getString(lable);
		        		if(count==1) {
		        			row1.createCell(i).setCellValue(lable);
		        		}
		        		row2.createCell(i).setCellValue(value);
		        	}
		        	count++;
		        }
	}

	public static void getsumyunwan(Map<String,Object>map,Sheet sheet,Connection connection) throws SQLException {
		//开始和结束时间
				String beginTime = (String) map.get("beginTime");
				String endTime = (String) map.get("endTime");
				//调用存储过程
		        CallableStatement cs = connection.prepareCall("{call getsumyunwan(?,?)}");
		        //存储过程传入参数
		        if(StringUtils.isBlank(beginTime)) {
		        	 cs.setString(1, "");
		             cs.setString(2, "");
		        }else {
		        	 beginTime = beginTime+"-01";
		        	 endTime = endTime+"-31";
		        	 cs.setString(1, beginTime);
		             cs.setString(2, endTime);
		        }

		        // ResultSet rs = cs.executeQuery(); //执行查询操作，并获取结果集
		        //执行存储过程
		        cs.execute();
		        // int rowCount = rs.getRow();
		        ResultSet resultSet = cs.getResultSet();
		        /*resultSet.last();
		        int rowCount = resultSet.getRow();
		        resultSet.beforeFirst();*/
		        ResultSetMetaData rsmd = resultSet.getMetaData() ;
		        int  columnCount = rsmd.getColumnCount();
		        int count = 1;
				Row row1 = sheet.createRow(0);
				//Sheet sheet2 = workbook.createSheet("sheet2") ;
		        while(resultSet.next())
		        {
		        	Row row2 = sheet.createRow(count);
		        	for(int i=1;i<=columnCount;i++) {
		        		String lable  = rsmd.getColumnLabel(i);
		            	String value = resultSet.getString(lable);
		        		if(count==1) {
		        			row1.createCell(i).setCellValue(lable);
		        		}
		        		row2.createCell(i).setCellValue(value);
		        	}
		        	count++;
		        }
	}

	public static void getsumfenmian(Map<String,Object>map,Sheet sheet,Connection connection) throws SQLException {
		//开始和结束时间
				String beginTime = (String) map.get("beginTime");
				String endTime = (String) map.get("endTime");
				//调用存储过程
		        CallableStatement cs = connection.prepareCall("{call getsumfenmian(?,?)}");
		        //存储过程传入参数
		        if(StringUtils.isBlank(beginTime)) {
		        	 cs.setString(1, "");
		             cs.setString(2, "");
		        }else {
		        	 beginTime = beginTime+"-01";
		        	 endTime = endTime+"-31";
		        	 cs.setString(1, beginTime);
		             cs.setString(2, endTime);
		        }

		        // ResultSet rs = cs.executeQuery(); //执行查询操作，并获取结果集
		        //执行存储过程
		        cs.execute();
		        // int rowCount = rs.getRow();
		        ResultSet resultSet = cs.getResultSet();
		        /*resultSet.last();
		        int rowCount = resultSet.getRow();
		        resultSet.beforeFirst();*/
		        ResultSetMetaData rsmd = resultSet.getMetaData() ;
		        int  columnCount = rsmd.getColumnCount();
		        int count = 1;
				Row row1 = sheet.createRow(0);
				//Sheet sheet2 = workbook.createSheet("sheet2") ;
		        while(resultSet.next())
		        {
		        	Row row2 = sheet.createRow(count);
		        	for(int i=1;i<=columnCount;i++) {
		        		String lable  = rsmd.getColumnLabel(i);
		            	String value = resultSet.getString(lable);
		        		if(count==1) {
		        			row1.createCell(i).setCellValue(lable);
		        		}
		        		row2.createCell(i).setCellValue(value);
		        	}
		        	count++;
		        }
	}

	public static void getsumychanru(Map<String,Object>map,Sheet sheet,Connection connection) throws SQLException {
		//开始和结束时间
				String beginTime = (String) map.get("beginTime");
				String endTime = (String) map.get("endTime");
				//调用存储过程
		        CallableStatement cs = connection.prepareCall("{call getsumychanru(?,?)}");
		        //存储过程传入参数
		        if(StringUtils.isBlank(beginTime)) {
		        	 cs.setString(1, "");
		             cs.setString(2, "");
		        }else {
		        	 beginTime = beginTime+"-01";
		        	 endTime = endTime+"-31";
		        	 cs.setString(1, beginTime);
		             cs.setString(2, endTime);
		        }

		        // ResultSet rs = cs.executeQuery(); //执行查询操作，并获取结果集
		        //执行存储过程
		        cs.execute();
		        // int rowCount = rs.getRow();
		        ResultSet resultSet = cs.getResultSet();
		        /*resultSet.last();
		        int rowCount = resultSet.getRow();
		        resultSet.beforeFirst();*/
		        ResultSetMetaData rsmd = resultSet.getMetaData() ;
		        int  columnCount = rsmd.getColumnCount();
		        int count = 1;
				Row row1 = sheet.createRow(0);
				//Sheet sheet2 = workbook.createSheet("sheet2") ;
		        while(resultSet.next())
		        {
		        	Row row2 = sheet.createRow(count);
		        	for(int i=1;i<=columnCount;i++) {
		        		String lable  = rsmd.getColumnLabel(i);
		            	String value = resultSet.getString(lable);
		        		if(count==1) {
		        			row1.createCell(i).setCellValue(lable);
		        		}
		        		row2.createCell(i).setCellValue(value);
		        	}
		        	count++;
		        }
	}

	//乐惠数据
	public void  queryLehui(Map<String,Object> map) throws Exception{
		Connection connection = null;
    	String url = "jdbc:mysql://rdsap8226j2iuruyoaamgpublic.mysql.rds.aliyuncs.com:3306/bbcare_cloud?createDatabaseIfNotExist=true&amp;amp;useUnicode=true&amp;amp;characterEncoding=utf8mb4&amp;amp;zeroDateTimeBehavior=convertToNull&amp;amp;transformedBitIsBoolean=true";
    	String username = "yunyin";
    	String password = "cl123456";
    	try {
			connection = DriverManager.getConnection(url, username, password);
		} catch (SQLException e) {

			e.printStackTrace();
		}
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");//格式化为年月
    	//开始和结束时间
		String beginTime = (String) map.get("beginTime");
		String endTime = (String) map.get("endTime");
		String sqlAdd = "";
		Map<String,Object> MapIn =  new HashMap<String,Object>(map);
		//计算两个时间中相差的月份
		if(!StringUtils.isBlank(beginTime)) {
			List <String> listMouth = DateUtil.daysBetweenmouth(beginTime,endTime);
			for(int i=0;i<listMouth.size();i++) {
				if(!StringUtils.isBlank(listMouth.get(i))) {
					sqlAdd = " where m.t3createTime>='"+listMouth.get(i)+"-01 00:00:00"+"' and m.t3createTime<='"+listMouth.get(i)+"-31 23:59:59"+"'";
				}
				MapIn.put("mouth", listMouth.get(i));
				List<Map<String, Object>> list = iUploadExcelDAO.selectOperationNote(MapIn);
				if(list!=null&&list.size()>0&&!listMouth.get(i).equals(sdf.format(new Date()))) {
					logger.info("已有导出数据!");
				}else {
					querylehui(connection,sqlAdd,listMouth.get(i),sdf.format(new Date()),map);
				}
			}
		}else {
			querylehui(connection,sqlAdd,"",sdf.format(new Date()),map);
		}

	}

	public void querylehui(Connection connection,String sqlAdd,String time,String nowDate,Map<String,Object> map) throws Exception {
		String sql = "select * from (SELECT t._accountName,b._babyName,b._gender,b._birthday,FLOOR(b.`_pregnancyWeek`/7) AS 孕周,b.`_pregnancyWeek`,a.`_birthLength`,a.`_birthWeight`,a.`_createTime`,a.`_fatherBirthday`,a.`_fatherEducation`,a.`_fatherProfession`,a.`_motherBirthday`,a.`_motherEducation`,a.`_motherProfession`,a.`_deliveryMethod`,a.`_pregnantCount`,a.`_city`,a.`_county`,a.`_province`,a.`_hospitalName`,a.`_address`,    \r\n" +
    			"t4._score as t4score,t5._score as t5score,t6._score as t6score,t7._score as t7score,t8._score as t8score,t9._score as t9score,\r\n" +
    			"t10._score as t10score,t11._score as t11score,t12._score as t12score,t13._note as t13note,t14._note as t1note,t3._createTime as t3createTime ,t3._babyAge       \r\n" +
    			"FROM t_archives a     \r\n" +
    			"INNER JOIN t_baby b ON a._babyId=b._babyId AND a._code IN(SELECT _code FROM t_wx_content)     \r\n" +
    			"INNER JOIN t_baby_t_account bb ON bb.baby_id=b._babyId    \r\n" +
    			"INNER JOIN t_account t ON bb.account_id=t._accountId    \r\n" +
    			"INNER JOIN     \r\n" +
    			"(SELECT qp._babyId,qp._id FROM t_babyquestionnairepackage qp ) AS t2 ON b._babyId=t2._babyId     \r\n" +
    			"INNER JOIN    \r\n" +
    			"(SELECT qr._babyQuestionnairePackage_id,qr._id,qr._createTime,qr._babyAge FROM t_babyquestionrecord qr ) AS t3 ON t2._id=t3._babyQuestionnairePackage_id      \r\n" +
    			"LEFT JOIN    \r\n" +
    			"(SELECT gs._score,gs._babyQuestionRecordId FROM t_babymodulegetscore gs WHERE  gs._questionModuleId='40288abe5167faf2015168029e7a0005' AND ISNULL(gs._score)=0)AS t4 ON t3._id=t4._babyQuestionRecordId    \r\n" +
    			"LEFT JOIN    \r\n" +
    			"(SELECT gs._score,gs._babyQuestionRecordId FROM t_babymodulegetscore gs WHERE  gs._questionModuleId='40288abe5167faf201516802c93a0006' AND ISNULL(gs._score)=0)AS t5 ON t3._id=t5._babyQuestionRecordId    \r\n" +
    			"LEFT JOIN    \r\n" +
    			"(SELECT gs._score,gs._babyQuestionRecordId FROM t_babymodulegetscore gs WHERE  gs._questionModuleId='40288abe5167faf20151680314a60007' AND ISNULL(gs._score)=0)AS t6 ON t3._id=t6._babyQuestionRecordId    \r\n" +
    			"LEFT JOIN    \r\n" +
    			"(SELECT gs._score,gs._babyQuestionRecordId FROM t_babymodulegetscore gs WHERE  gs._questionModuleId='40288abe5167faf201516803403e0008' AND ISNULL(gs._score)=0)AS t7 ON t3._id=t7._babyQuestionRecordId    \r\n" +
    			"LEFT JOIN    \r\n" +
    			"(SELECT gs._score,gs._babyQuestionRecordId FROM t_babymodulegetscore gs WHERE  gs._questionModuleId='40288abe5167faf201516803864a0009' AND ISNULL(gs._score)=0)AS t8 ON t3._id=t8._babyQuestionRecordId    \r\n" +
    			"LEFT JOIN    \r\n" +
    			"(SELECT gs._score,gs._babyQuestionRecordId FROM t_babymodulegetscore gs WHERE  gs._questionModuleId='40288abe5167faf20151680235bd0002' AND ISNULL(gs._score)=0)AS t9 ON t3._id=t9._babyQuestionRecordId    \r\n" +
    			"LEFT JOIN    \r\n" +
    			"(SELECT gs._score,gs._babyQuestionRecordId FROM t_babymodulegetscore gs WHERE  gs._questionModuleId='40288abe5167faf201516802502e0003' AND ISNULL(gs._score)=0)AS t10 ON t3._id=t10._babyQuestionRecordId    \r\n" +
    			"LEFT JOIN    \r\n" +
    			"(SELECT gs._score,gs._babyQuestionRecordId FROM t_babymodulegetscore gs WHERE  gs._questionModuleId='40288abe5167faf2015168026e890004' AND ISNULL(gs._score)=0)AS t11 ON t3._id=t11._babyQuestionRecordId    \r\n" +
    			"LEFT JOIN    \r\n" +
    			"(SELECT gs._score,gs._babyQuestionRecordId FROM t_babymodulegetscore gs WHERE  gs._questionModuleId='40288abe5167faf2015168026e890006' AND ISNULL(gs._score)=0)AS t12 ON t3._id=t12._babyQuestionRecordId    \r\n" +
    			"LEFT JOIN    \r\n" +
    			"(SELECT gs._note,gs._babyQuestionRecord_id FROM t_babyquestiondetail gs WHERE  gs._question_name = '您宝宝的体重是多少？（kg）' AND ISNULL(gs._note)=0)AS t13 ON t3._id=t13._babyQuestionRecord_id    \r\n" +
    			"LEFT JOIN    \r\n" +
    			"(SELECT gs._note,gs._babyQuestionRecord_id FROM t_babyquestiondetail gs WHERE  gs._question_name = '您宝宝的身长是多少？（cm）' AND ISNULL(gs._note)=0)AS t14 ON t3._id=t14._babyQuestionRecord_id ) m"+sqlAdd+";";
		Statement statement = connection.createStatement();
		logger.info(sql);
		ResultSet resultSet = statement.executeQuery(sql);
		Workbook workbook = new SXSSFWorkbook(100);
		//HSSFWorkbook workbook = new HSSFWorkbook();
		Sheet sheet = workbook.createSheet();
		Sheet sheet2 = workbook.createSheet("sheet2") ;

		//HSSFSheet sheet = workbook.createSheet();
		//HSSFSheet sheet2 = workbook.createSheet("sheet2") ;

		Row row1 = sheet.createRow(0);
		row1.createCell(0).setCellValue("账号");
		row1.createCell(1).setCellValue("姓名");
		row1.createCell(2).setCellValue("性别");
		row1.createCell(3).setCellValue("宝宝生日");
		row1.createCell(4).setCellValue("分娩孕周（周）");
		row1.createCell(5).setCellValue("分娩孕周（天）");
		row1.createCell(6).setCellValue("出生身长");
		row1.createCell(7).setCellValue("出生体重");
		row1.createCell(8).setCellValue("建档时间");
		row1.createCell(9).setCellValue("父亲生日");
		row1.createCell(10).setCellValue("父亲受教育年限");
		row1.createCell(11).setCellValue("父亲工作");
		row1.createCell(12).setCellValue("母亲生日");
		row1.createCell(13).setCellValue("母亲受教育年限");
		row1.createCell(14).setCellValue("母亲职业");
		row1.createCell(15).setCellValue("分娩方式");
		row1.createCell(16).setCellValue("怀孕次数");
		row1.createCell(17).setCellValue("所在城市");
		row1.createCell(18).setCellValue("地区");
		row1.createCell(19).setCellValue("省");
		row1.createCell(20).setCellValue("就诊医院");
		row1.createCell(21).setCellValue("地址");
		row1.createCell(22).setCellValue("智能-沟通（分数）");
		row1.createCell(23).setCellValue("智能-沟通（分类）");
		row1.createCell(24).setCellValue("智能-粗大运动（分数）");
		row1.createCell(25).setCellValue("智能-粗大运动（分类）");
		row1.createCell(26).setCellValue("智能-精细运动（分数）");
		row1.createCell(27).setCellValue("智能-精细运动（分类）");
		row1.createCell(28).setCellValue("智能-解决问题（分数）");
		row1.createCell(29).setCellValue("智能-解决问题（分类）");
		row1.createCell(30).setCellValue("智能-个人社会（分数）");
		row1.createCell(31).setCellValue("智能-个人社会（分类）");
		row1.createCell(32).setCellValue("养育环境-活动空间（分数）");
		row1.createCell(33).setCellValue("养育环境-活动空间（分类）");
		row1.createCell(34).setCellValue("养育环境-活动多样性（分数）");
		row1.createCell(35).setCellValue("养育环境-活动多样性（分类）");
		row1.createCell(36).setCellValue("养育环境-粗大运动玩具（分数）");
		row1.createCell(37).setCellValue("养育环境-粗大运动玩具（分类）");
		row1.createCell(38).setCellValue("养育环境-精细运动玩具（分数）");
		row1.createCell(39).setCellValue("养育环境-精细运动玩具（分类）");
		row1.createCell(40).setCellValue("体重(分数)");
		row1.createCell(41).setCellValue("体重(分类)");
		row1.createCell(42).setCellValue("身高(分数)");
		row1.createCell(43).setCellValue("身高(分类)");
		row1.createCell(44).setCellValue("测试评估日期");

		int count = 1;
		boolean falg = false;
		while (resultSet.next()) {
			//每隔65535条记录后，创建新的sheet
			if (count % 65535== 0) {
				count = 1;
				falg = true;

				Row row2 = sheet2.createRow(0);
				row2.createCell(0).setCellValue("账号");
				row2.createCell(1).setCellValue("姓名");
				row2.createCell(2).setCellValue("性别");
				row2.createCell(3).setCellValue("宝宝生日");
				row2.createCell(4).setCellValue("分娩孕周（周）");
				row2.createCell(5).setCellValue("分娩孕周（天）");
				row2.createCell(6).setCellValue("出生身长");
				row2.createCell(7).setCellValue("出生体重");
				row2.createCell(8).setCellValue("建档时间");
				row2.createCell(9).setCellValue("父亲生日");
				row2.createCell(10).setCellValue("父亲受教育年限");
				row2.createCell(11).setCellValue("父亲工作");
				row2.createCell(12).setCellValue("母亲生日");
				row2.createCell(13).setCellValue("母亲受教育年限");
				row2.createCell(14).setCellValue("母亲职业");
				row2.createCell(15).setCellValue("分娩方式");
				row2.createCell(16).setCellValue("怀孕次数");
				row2.createCell(17).setCellValue("所在城市");
				row2.createCell(18).setCellValue("地区");
				row2.createCell(19).setCellValue("省");
				row2.createCell(20).setCellValue("就诊医院");
				row2.createCell(21).setCellValue("地址");
				row2.createCell(22).setCellValue("智能-沟通（分数）");
				row2.createCell(23).setCellValue("智能-沟通（分类）");
				row2.createCell(24).setCellValue("智能-粗大运动（分数）");
				row2.createCell(25).setCellValue("智能-粗大运动（分类）");
				row2.createCell(26).setCellValue("智能-精细运动（分数）");
				row2.createCell(27).setCellValue("智能-精细运动（分类）");
				row2.createCell(28).setCellValue("智能-解决问题（分数）");
				row2.createCell(29).setCellValue("智能-解决问题（分类）");
				row2.createCell(30).setCellValue("智能-个人社会（分数）");
				row2.createCell(31).setCellValue("智能-个人社会（分类）");
				row2.createCell(32).setCellValue("养育环境-活动空间（分数）");
				row2.createCell(33).setCellValue("养育环境-活动空间（分类）");
				row2.createCell(34).setCellValue("养育环境-活动多样性（分数）");
				row2.createCell(35).setCellValue("养育环境-活动多样性（分类）");
				row2.createCell(36).setCellValue("养育环境-粗大运动玩具（分数）");
				row2.createCell(37).setCellValue("养育环境-粗大运动玩具（分类）");
				row2.createCell(38).setCellValue("养育环境-精细运动玩具（分数）");
				row2.createCell(39).setCellValue("养育环境-精细运动玩具（分类）");
				row2.createCell(40).setCellValue("体重(分数)");
				row2.createCell(41).setCellValue("体重(分类)");
				row2.createCell(42).setCellValue("身高(分数)");
				row2.createCell(43).setCellValue("身高(分类)");
				row2.createCell(44).setCellValue("测试评估日期");
			}

		   if (falg) {
			    // 创建工作表

			   Row row = sheet2.createRow(count);
				row.createCell(0).setCellValue(resultSet.getString(1));
				row.createCell(1).setCellValue(resultSet.getString(2));
				String babyAge = resultSet.getString("_babyAge");
				int dayAge = Integer.parseInt(babyAge);
				if (resultSet.getString(3).equals("N")) {
					row.createCell(2).setCellValue("男");
				}else {
					row.createCell(2).setCellValue("女");
				}
				row.createCell(3).setCellValue(resultSet.getString(4));
				row.createCell(4).setCellValue(resultSet.getString(5));
				row.createCell(5).setCellValue(resultSet.getString(6));
				row.createCell(6).setCellValue(resultSet.getString(7));
				row.createCell(7).setCellValue(resultSet.getString(8));
				row.createCell(8).setCellValue(resultSet.getString(9).substring(0, 10));
				row.createCell(9).setCellValue(resultSet.getString(10));
				row.createCell(10).setCellValue(resultSet.getString(11));
				row.createCell(11).setCellValue(resultSet.getString(12));
				row.createCell(12).setCellValue(resultSet.getString(13));
				row.createCell(13).setCellValue(resultSet.getString(14));
				row.createCell(14).setCellValue(resultSet.getString(15));
				row.createCell(15).setCellValue(resultSet.getString(16));
				row.createCell(16).setCellValue(resultSet.getString(17));
				row.createCell(17).setCellValue(resultSet.getString(18));
				row.createCell(18).setCellValue(resultSet.getString(19));
				row.createCell(19).setCellValue(resultSet.getString(20));
				row.createCell(20).setCellValue(resultSet.getString(21));
				row.createCell(21).setCellValue(resultSet.getString(22));

				row.createCell(22).setCellValue(resultSet.getString(23));
				String gouTong = EvaluateUtils.getResult(dayAge, resultSet.getDouble(23), "智能发育", "沟通");
				if (resultSet.getString(23) == null) {
					gouTong = null;
				}
				row.createCell(23).setCellValue(gouTong);	//沟通分类

				row.createCell(24).setCellValue(resultSet.getString(24));
				String cuDa = EvaluateUtils.getResult(dayAge, resultSet.getDouble(24), "智能发育", "粗大动作");
				if (resultSet.getString(24) == null) {
					cuDa = null;
				}
				row.createCell(25).setCellValue(cuDa);

				row.createCell(26).setCellValue(resultSet.getString(25));
				String jingXi = EvaluateUtils.getResult(dayAge, resultSet.getDouble(25), "智能发育", "精细运动");
				if (resultSet.getString(25) == null) {
					jingXi = null;
				}
				row.createCell(27).setCellValue(jingXi);

				row.createCell(28).setCellValue(resultSet.getString(26));
				String jieJue = EvaluateUtils.getResult(dayAge, resultSet.getDouble(26), "智能发育", "解决问题");
				if (resultSet.getString(26) == null) {
					jieJue = null;
				}
				row.createCell(29).setCellValue(jieJue);

				row.createCell(30).setCellValue(resultSet.getString(27));
				String sheHui = EvaluateUtils.getResult(dayAge, resultSet.getDouble(27), "智能发育", "个人-社会");
				if (resultSet.getString(27) == null) {
					sheHui = null;
				}
				row.createCell(31).setCellValue(sheHui);

				row.createCell(32).setCellValue(resultSet.getString(28));
				String kongJian = EvaluateUtils.getResult(dayAge, resultSet.getDouble(28), "运动环境", "活动空间");
				if (resultSet.getString(28) == null) {
					kongJian = null;
				}
				row.createCell(33).setCellValue(kongJian);

				row.createCell(34).setCellValue(resultSet.getString(29));
				String duoYang = EvaluateUtils.getResult(dayAge, resultSet.getDouble(29), "运动环境", "活动多样性");
				if (resultSet.getString(29) == null) {
					duoYang = null;
				}
				row.createCell(35).setCellValue(duoYang);


				row.createCell(36).setCellValue(resultSet.getString(30));
				String CDWJ = EvaluateUtils.getResult(dayAge, resultSet.getDouble(30), "运动环境", "粗大运动玩具");
				if (resultSet.getString(30) == null) {
					CDWJ = null;
				}
				row.createCell(37).setCellValue(CDWJ);

				row.createCell(38).setCellValue(resultSet.getString(31));
				String JXWJ = EvaluateUtils.getResult(dayAge, resultSet.getDouble(31), "运动环境", "精细运动玩具");
				if (resultSet.getString(31) == null) {
					JXWJ = null;
				}
				row.createCell(39).setCellValue(JXWJ);

				row.createCell(40).setCellValue(resultSet.getString(32));
				String tiZhong = EvaluateUtils.getWeightResult(dayAge, resultSet.getDouble(32), resultSet.getString(3));
				if (resultSet.getString(32) == null) {
					tiZhong = null;
				}
				row.createCell(41).setCellValue(tiZhong);

				row.createCell(42).setCellValue(resultSet.getString(33));
				String shenGao = EvaluateUtils.getHeightResult(dayAge, resultSet.getDouble(33), resultSet.getString(3));
				if (resultSet.getString(33) == null) {
					shenGao = null;
				}
				row.createCell(43).setCellValue(shenGao);

				row.createCell(44).setCellValue(resultSet.getString(34).substring(0, 10));
				count++;
		   }else {
			   Row row = sheet.createRow(count);
				row.createCell(0).setCellValue(resultSet.getString(1));
				row.createCell(1).setCellValue(resultSet.getString(2));
				String babyAge = resultSet.getString("_babyAge");
				int dayAge = Integer.parseInt(babyAge);
				if (resultSet.getString(3).equals("N")) {
					row.createCell(2).setCellValue("男");
				}else {
					row.createCell(2).setCellValue("女");
				}
				row.createCell(3).setCellValue(resultSet.getString(4));
				row.createCell(4).setCellValue(resultSet.getString(5));
				row.createCell(5).setCellValue(resultSet.getString(6));
				row.createCell(6).setCellValue(resultSet.getString(7));
				row.createCell(7).setCellValue(resultSet.getString(8));
				row.createCell(8).setCellValue(resultSet.getString(9).substring(0, 10));
				row.createCell(9).setCellValue(resultSet.getString(10));
				row.createCell(10).setCellValue(resultSet.getString(11));
				row.createCell(11).setCellValue(resultSet.getString(12));
				row.createCell(12).setCellValue(resultSet.getString(13));
				row.createCell(13).setCellValue(resultSet.getString(14));
				row.createCell(14).setCellValue(resultSet.getString(15));
				row.createCell(15).setCellValue(resultSet.getString(16));
				row.createCell(16).setCellValue(resultSet.getString(17));
				row.createCell(17).setCellValue(resultSet.getString(18));
				row.createCell(18).setCellValue(resultSet.getString(19));
				row.createCell(19).setCellValue(resultSet.getString(20));
				row.createCell(20).setCellValue(resultSet.getString(21));
				row.createCell(21).setCellValue(resultSet.getString(22));

				row.createCell(22).setCellValue(resultSet.getString(23));
				String gouTong = EvaluateUtils.getResult(dayAge, resultSet.getDouble(23), "智能发育", "沟通");
				if (resultSet.getString(23) == null) {
					gouTong = null;
				}
				row.createCell(23).setCellValue(gouTong);	//沟通分类

				row.createCell(24).setCellValue(resultSet.getString(24));
				String cuDa = EvaluateUtils.getResult(dayAge, resultSet.getDouble(24), "智能发育", "粗大动作");
				if (resultSet.getString(24) == null) {
					cuDa = null;
				}
				row.createCell(25).setCellValue(cuDa);

				row.createCell(26).setCellValue(resultSet.getString(25));
				String jingXi = EvaluateUtils.getResult(dayAge, resultSet.getDouble(25), "智能发育", "精细运动");
				if (resultSet.getString(25) == null) {
					jingXi = null;
				}
				row.createCell(27).setCellValue(jingXi);

				row.createCell(28).setCellValue(resultSet.getString(26));
				String jieJue = EvaluateUtils.getResult(dayAge, resultSet.getDouble(26), "智能发育", "解决问题");
				if (resultSet.getString(26) == null) {
					jieJue = null;
				}
				row.createCell(29).setCellValue(jieJue);

				row.createCell(30).setCellValue(resultSet.getString(27));
				String sheHui = EvaluateUtils.getResult(dayAge, resultSet.getDouble(27), "智能发育", "个人-社会");
				if (resultSet.getString(27) == null) {
					sheHui = null;
				}
				row.createCell(31).setCellValue(sheHui);

				row.createCell(32).setCellValue(resultSet.getString(28));
				String kongJian = EvaluateUtils.getResult(dayAge, resultSet.getDouble(28), "运动环境", "活动空间");
				if (resultSet.getString(28) == null) {
					kongJian = null;
				}
				row.createCell(33).setCellValue(kongJian);

				row.createCell(34).setCellValue(resultSet.getString(29));
				String duoYang = EvaluateUtils.getResult(dayAge, resultSet.getDouble(29), "运动环境", "活动多样性");
				if (resultSet.getString(29) == null) {
					duoYang = null;
				}
				row.createCell(35).setCellValue(duoYang);


				row.createCell(36).setCellValue(resultSet.getString(30));
				String CDWJ = EvaluateUtils.getResult(dayAge, resultSet.getDouble(30), "运动环境", "粗大运动玩具");
				if (resultSet.getString(30) == null) {
					CDWJ = null;
				}
				row.createCell(37).setCellValue(CDWJ);

				row.createCell(38).setCellValue(resultSet.getString(31));
				String JXWJ = EvaluateUtils.getResult(dayAge, resultSet.getDouble(31), "运动环境", "精细运动玩具");
				if (resultSet.getString(31) == null) {
					JXWJ = null;
				}
				row.createCell(39).setCellValue(JXWJ);

				row.createCell(40).setCellValue(resultSet.getString(32));
				String tiZhong = EvaluateUtils.getWeightResult(dayAge, resultSet.getDouble(32), resultSet.getString(3));
				if (resultSet.getString(32) == null) {
					tiZhong = null;
				}
				row.createCell(41).setCellValue(tiZhong);

				row.createCell(42).setCellValue(resultSet.getString(33));
				String shenGao = EvaluateUtils.getHeightResult(dayAge, resultSet.getDouble(33), resultSet.getString(3));
				if (resultSet.getString(33) == null) {
					shenGao = null;
				}
				row.createCell(43).setCellValue(shenGao);

				row.createCell(44).setCellValue(resultSet.getString(34).substring(0, 10));
				count++;
		   }

		}

		String fileName = "C:\\Users\\Administrator\\Desktop\\upload\\乐惠"+time+".xls";
		OutputStream outputStream = new FileOutputStream(new File(fileName));
		workbook.write(outputStream);
		workbook.close();
		OperationNote OperationNote = new OperationNote();
		String id = SeqUtil.getSeqNo(Constants.SEQ_NO_FOR_SHUJUDAOCHU);
		OperationNote.setId(id);
		OperationNote.setTalentId((String)map.get("talentId"));
		OperationNote.setDeptId((String)map.get("deptId"));
		OperationNote.setDoctor_id((String)map.get("authorId"));
		OperationNote.setDoctor_name((String)map.get("authorName"));
		OperationNote.setBak1("");
		OperationNote.setBak2("");
		OperationNote.setBak3("");
		OperationNote.setMouth(time);
		OperationNote.setProject_id((String)map.get("projectId"));
		OperationNote.setProject_name((String)map.get("projectName"));
		OperationNote.setQueueId((String)map.get("queueId"));
		OperationNote.setUpdate_time((String)map.get("updateTime"));
		OperationNote.setCreate_time((String)map.get("createTime"));
		if(!StringUtils.isBlank(time) && time.equals(nowDate)) {
			logger.info("当前月份先更新，没有在上传！");
			uploadFile(fileName);
			Map<String,Object> map1 = new HashMap<String,Object>();
			map1.put("projectId", (String)map.get("projectId"));
			map1.put("projectName", (String)map.get("projectName"));
			map1.put("talentId", (String)map.get("talentId"));
			map1.put("mouth", time);
			map1.put("updateTime", (String)map.get("updateTime"));
			int flag = iUploadExcelDAO.updateOperationNote(map1);
			if(flag<=0) {
				Map<String,Object> mapOut = uploadFile(fileName);
				OperationNote.setFile_name((String)mapOut.get("name"));
				OperationNote.setFileurl((String)mapOut.get("url"));
				iUploadExcelDAO.saveOperationNote(OperationNote);
			}
		}else if(!StringUtils.isBlank(time) && !time.equals(nowDate)) {
			Map<String,Object> mapOut = uploadFile(fileName);
			OperationNote.setFile_name((String)mapOut.get("name"));
			OperationNote.setFileurl((String)mapOut.get("url"));
			iUploadExcelDAO.saveOperationNote(OperationNote);
		}
	}
	//贝莉
	public void  queryBreastBeili(Map<String,Object> mapIn) throws Exception{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");//格式化为年月
    	//开始和结束时间
		String beginTime = (String) mapIn.get("beginTime");
		String endTime = (String) mapIn.get("endTime");
		//String sqlAdd = "";
		Map<String,Object> MapIn =  new HashMap<String,Object>(mapIn);
		//计算两个时间中相差的月份
		if(!StringUtils.isBlank(beginTime)) {
			List <String> listMouth = DateUtil.daysBetweenmouth(beginTime,endTime);
			for(int i=0;i<listMouth.size();i++) {
				MapIn.put("mouth", listMouth.get(i));
				List<Map<String, Object>> list = iUploadExcelDAO.selectOperationNote(MapIn);
				if(list!=null&&list.size()>0&&!listMouth.get(i).equals(sdf.format(new Date()))) {
					logger.info("已有导出数据!");
				}else {
					querybreastbeili(listMouth.get(i),sdf.format(new Date()),mapIn);
				}
			}
		}else {
			querybreastbeili("",sdf.format(new Date()),mapIn);
		}
	}

	private void querybreastbeili(String time,String nowDate,Map<String,Object> mapIn) throws Exception {
		//查询患者 + 记录
				Map<String,Object> paramMap = new HashMap<String,Object>();
				List<String> queueList = new ArrayList<String>();
				//String queueId ="12SHYFY000000001";//一妇婴:12SHYFY000000001  吴江 ：12SHYFY000000019
				String tenantId ="SHYFY0001";
				//String deptId="shyFyJdept10001";//一妇婴:shyFyJdept10001  吴江 ：shyFyJdept10019
				//String shequ="18862163677";
				String [] str = {
						"12SHYFY000000001",
						"12SHYFY000000002",
						"12SHYFY000000003",
						"12SHYFY000000004",
						"12SHYFY000000005",
						"12SHYFY000000006",
						"12SHYFY000000007",
						"12SHYFY000000008",
						"12SHYFY000000009",
						"12SHYFY000000010",
						"12SHYFY000000011",
						"12SHYFY000000012",
						"12SHYFY000000013",
						"12SHYFY000000014",
						"12SHYFY000000015",
						"12SHYFY000000016",
						"12SHYFY000000017",
						"12SHYFY000000018",
						"12SHYFY000000019",
						"12SHYFY000000020",
						"12SHYFY000000021",
						"12SHYFY000000022",
						"12SHYFY000000023",
						"12SHYFY000000024"
				};
				for(int i=0;i<str.length;i++) {
					queueList.add(str[i]);
				}
				paramMap.put("examinationPaperName","BaileyScreening");
				paramMap.put("queueIdIn",queueList);
				paramMap.put("tenantId",tenantId);
				paramMap.put("beginTime",time+"-01 00:00:00");
				paramMap.put("endTime",time+"-31 23:59:59");
				List<Map<String,Object>> records = followEvaluationDao.selectEvaluationResultAll(paramMap);

				//查询患者建档资料
				if(!CollectionUtils.isEmpty(records)){
					for(int i =0 ;i<records.size();i++){
//								String userId = records.get(i).get("userId").toString();
						String ptSchemeId= records.get(i).get("ptSchemeId").toString();
						String queueId = records.get(i).get("queueId").toString();
						String deptId = records.get(i).get("deptId").toString();
				        paramMap.clear();
				        paramMap.put("seqNo", Constants.TASK_SEQ_FOR_INIT);
				        paramMap.put("ptSchemeId",ptSchemeId);
						// 查询taskid
						List<PatientTask> taskList = patientTaskDao.select(paramMap);
						String taskId ="";
						if (!CollectionUtils.isEmpty(taskList)) {
							taskId = taskList.get(0).getId();
						}

						paramMap.clear();
						paramMap.put("tenantId", tenantId);
						paramMap.put("groupType", Constants.TENANT_GROUP_TYPE_FOR_MULCENTER);
						paramMap.put("rootGroupId", deptId);
				        if (null == queueId || "".equals(queueId)) {
				            throw (new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_INPUT_DATA_VERIFY_ERROR, "入参节点错误，未传入队列id或值为空！"));
				        }
				        paramMap.put("taskId", taskId);
				        paramMap.put("queueId", queueId);
				        Map<String, Object> retMap = patientSerivce.qryPatientContentList(paramMap);
//						        logger.info(retMap.get("values").toString());
				        JSONObject questiones =JSONObject.parseObject(JSON.toJSONString(retMap.get("values")));
				        String birthWeight = questiones.getString("Pub2200001");
				        String motherBitrhday = questiones.getString("Pub2200004");
				        String idiccid = questiones.getString("Pub2200003");

				        String babysex = questiones.getString("Pub1100003");//性别
				        String childbirth = questiones.getString("Pub12x01003");//分娩方式
				        String heightOfDay = questiones.getString("Pub12x01004");//测试当天身高
				        String weightOfDay = questiones.getString("Pub12x01005");//测试当天体重
				        String headLengthOfDay = questiones.getString("Pub12x01006");//测试当天头围
				        String pregnanciesNum = questiones.getString("Pub12x01007");//母亲怀孕次数
				        String childbirthNum = questiones.getString("Pub12x01008");//母亲分娩次数
				        String matherCulture = questiones.getString("Pub12x01001");//母亲文化程度
				        String fatherCulture = questiones.getString("Pub12x01002");//父亲文化程度

				        int weight =0;
				        float weightf =0;
				        try {
				        	weight =  Integer.parseInt(birthWeight);
				        	weightf = (float)weight/1000;
						} catch (Exception e) {
							weightf = (float) Double.parseDouble(birthWeight);
						}
				        records.get(i).put("birthWeight",weightf);
				        records.get(i).put("motherBitrhday",motherBitrhday);
				        records.get(i).put("idiccid",idiccid);

				        records.get(i).put("babysex",babysex);
				        records.get(i).put("childbirth",childbirth);
				        records.get(i).put("heightOfDay",heightOfDay);
				        records.get(i).put("weightOfDay",weightOfDay);
				        records.get(i).put("headLengthOfDay",headLengthOfDay);
				        records.get(i).put("pregnanciesNum",pregnanciesNum);
				        records.get(i).put("childbirthNum",childbirthNum);
				        records.get(i).put("matherCulture",matherCulture);
				        records.get(i).put("fatherCulture",fatherCulture);

				        if(null == records.get(i).get("testTime")){
					        records.get(i).put("testTime",records.get(i).get("createTime").toString().substring(0,10));
				        }else{
					        records.get(i).put("testTime",records.get(i).get("testTime").toString());
				        }
				        //
				        String score = (String)records.get(i).get("score");
				        String pregnancDayStr = records.get(i).get("pregnancDay").toString();
//						        String expectedDay = records.get(i).get("expectedDay").toString();
				        String birthday  = records.get(i).get("birthday").toString();
				        String testTime = records.get(i).get("testTime").toString();
				        int pregnancDay = Integer.parseInt(pregnancDayStr);
				        records.get(i).put("pregnancWeek",pregnancDay/7);

				        long correctBirth = ToolUtils.getCorrect(birthday, pregnancDay);
				        records.get(i).put("crrectAge", ToolUtils.getCommAgeByBirthday(testTime,DateUtil.getDate_8(new Date(correctBirth))));
						int ageMonth = ToolUtils.getAgeMonthByBirthday(testTime,DateUtil.getDate_8(new Date(correctBirth)));
				        records.get(i).put("ageMonth", ageMonth);
				        long day = 	(long)((DateUtil.getDate(testTime).getTime()-correctBirth)/(1000*60*60*24));

				        JSONObject json = JSONObject.parseObject(score);
				        int bigAction = json.getIntValue("bigAction"); //大动作
				        int express = json.getIntValue("express");//语言表达
				        int fineMotor = json.getIntValue("fineMotor"); //精细
				        int understand = json.getIntValue("understand");//语言理解
				        int cognitive = json.getIntValue("cognitive");//语言理解

				        records.get(i).put("bigAction", bigAction);
				        records.get(i).put("express", express);
				        records.get(i).put("fineMotor", fineMotor);
				        records.get(i).put("understand", understand);
				        records.get(i).put("cognitive", cognitive);

				        String WARN="边缘",NORMAL="无明显异常",DANGEROUS="存在落后风险";
				        String cognitiveResult  ="";
				        String expressResult  ="";
				        String fineMotorResult  ="";
				        String bigActionResult  ="";
				        String understandResult  ="";

				        if (16 <= day && day <= 3 * 30 + 15) {
				            if (0 <= cognitive && cognitive <= 2) cognitiveResult = WARN;
				            if (3 <= cognitive && cognitive <= 33) cognitiveResult = NORMAL;

				            if (0 == understand)    understandResult = DANGEROUS;
				            if (0 < understand && understand <= 2) understandResult = WARN;
				            if (3 <= understand && understand <= 24) understandResult = NORMAL;

				            if (0 <= express && express <= 1) expressResult = WARN;
				            if (2 <= express && express <= 24) expressResult = NORMAL;

				            if (0 <= fineMotor && fineMotor <= 2) fineMotorResult = WARN;
				            if (3 <= fineMotor && fineMotor <= 27) fineMotorResult = NORMAL;

				            if (0 <= bigAction && bigAction <= 2) bigActionResult = WARN;
				            if (3 <= bigAction && bigAction <= 28) bigActionResult = NORMAL;

				        } else if (3 * 30 + 16 <= day && day <= 6 * 30 + 15) {
				            if (0 <= cognitive && cognitive <= 3) cognitiveResult = DANGEROUS;
				            if (4 <= cognitive && cognitive <= 6) cognitiveResult = WARN;
				            if (7 <= cognitive && cognitive <= 33) cognitiveResult = NORMAL;

				            if (0 <= understand && understand <= 3)    understandResult = DANGEROUS;
				            if (4 <= understand && understand <= 5) understandResult = WARN;
				            if (6 <= understand && understand <= 24) understandResult = NORMAL;

				            if (0 <= express && express <= 2) expressResult = DANGEROUS;
				            if (3 <= express && express <= 4) expressResult = WARN;
				            if (5 <= express && express <= 24) expressResult = NORMAL;

				            if (0 <= fineMotor && fineMotor <= 3) fineMotorResult = DANGEROUS;
				            if (4 <= fineMotor && fineMotor <= 6) fineMotorResult = WARN;
				            if (7 <= fineMotor && fineMotor <= 27) fineMotorResult = NORMAL;

				            if (0 <= bigAction && bigAction <= 4) bigActionResult = DANGEROUS;
				            if (5 <= bigAction && bigAction <= 6) bigActionResult = WARN;
				            if (7 <= bigAction && bigAction <= 28) bigActionResult = NORMAL;

				        } else if (6 * 30 + 16 <= day && day <= 9 * 30 + 15) {
				            if (0 <= cognitive && cognitive <= 6) cognitiveResult = DANGEROUS;
				            if (7 <= cognitive && cognitive <= 9) cognitiveResult = WARN;
				            if (10 <= cognitive && cognitive <= 33) cognitiveResult = NORMAL;

				            if (0 <= understand && understand <= 5)    understandResult = DANGEROUS;
				            if (6 <= understand && understand <= 7) understandResult = WARN;
				            if (8 <= understand && understand <= 24) understandResult = NORMAL;

				            if (0 <= express && express <= 3) expressResult = DANGEROUS;
				            if (4 <= express && express <= 5) expressResult = WARN;
				            if (6 <= express && express <= 24) expressResult = NORMAL;

				            if (0 <= fineMotor && fineMotor <= 6) fineMotorResult = DANGEROUS;
				            if (7 <= fineMotor && fineMotor <= 8) fineMotorResult = WARN;
				            if (9 <= fineMotor && fineMotor <= 27) fineMotorResult = NORMAL;

				            if (0 <= bigAction && bigAction <= 7) bigActionResult = DANGEROUS;
				            if (8 <= bigAction && bigAction <= 10) bigActionResult = WARN;
				            if (11 <= bigAction && bigAction <= 28) bigActionResult = NORMAL;

				        } else if (9 * 30 + 16 <= day && day <= 12 * 30 + 15) {
				            if (0 <= cognitive && cognitive <= 9) cognitiveResult = DANGEROUS;
				            if (10 <= cognitive && cognitive <= 13) cognitiveResult = WARN;
				            if (14 <= cognitive && cognitive <= 33) cognitiveResult = NORMAL;

				            if (0 <= understand && understand <= 6)    understandResult = DANGEROUS;
				            if (7 <= understand && understand <= 9) understandResult = WARN;
				            if (10 <= understand && understand <= 24) understandResult = NORMAL;

				            if (0 <= express && express <= 4) expressResult = DANGEROUS;
				            if (5 <= express && express <= 8) expressResult = WARN;
				            if (9 <= express && express <= 24) expressResult = NORMAL;

				            if (0 <= fineMotor && fineMotor <= 8) fineMotorResult = DANGEROUS;
				            if (9 <= fineMotor && fineMotor <= 10) fineMotorResult = WARN;
				            if (11 <= fineMotor && fineMotor <= 27) fineMotorResult = NORMAL;

				            if (0 <= bigAction && bigAction <= 10) bigActionResult = DANGEROUS;
				            if (11 <= bigAction && bigAction <= 12) bigActionResult = WARN;
				            if (13 <= bigAction && bigAction <= 28) bigActionResult = NORMAL;

				        } else if (12 * 30 + 16 <= day && day <= 18 * 30 + 15) {
				            if (0 <= cognitive && cognitive <= 13) cognitiveResult = DANGEROUS;
				            if (14 <= cognitive && cognitive <= 16) cognitiveResult = WARN;
				            if (17 <= cognitive && cognitive <= 33) cognitiveResult = NORMAL;

				            if (0 <= understand && understand <= 9)    understandResult = DANGEROUS;
				            if (10 <= understand && understand <= 11) understandResult = WARN;
				            if (12 <= understand && understand <= 24) understandResult = NORMAL;

				            if (0 <= express && express <= 9) expressResult = DANGEROUS;
				            if (10 <= express && express <= 12) expressResult = WARN;
				            if (13 <= express && express <= 24) expressResult = NORMAL;

				            if (0 <= fineMotor && fineMotor <= 10) fineMotorResult = DANGEROUS;
				            if (11 <= fineMotor && fineMotor <= 13) fineMotorResult = WARN;
				            if (14 <= fineMotor && fineMotor <= 27) fineMotorResult = NORMAL;

				            if (0 <= bigAction && bigAction <= 12) bigActionResult = DANGEROUS;
				            if (13 <= bigAction && bigAction <= 16) bigActionResult = WARN;
				            if (17 <= bigAction && bigAction <= 28) bigActionResult = NORMAL;

				        } else if (18 * 30 + 16 <= day && day <= 24 * 30 + 15) {
				            if (0 <= cognitive && cognitive <= 16) cognitiveResult = DANGEROUS;
				            if (17 <= cognitive && cognitive <= 20) cognitiveResult = WARN;
				            if (21 <= cognitive && cognitive <= 33) cognitiveResult = NORMAL;

				            if (0 <= understand && understand <= 11)    understandResult = DANGEROUS;
				            if (12 <= understand && understand <= 15) understandResult = WARN;
				            if (16 <= understand && understand <= 24) understandResult = NORMAL;

				            if (0 <= express && express <= 11) expressResult = DANGEROUS;
				            if (12 <= express && express <= 15) expressResult = WARN;
				            if (16 <= express && express <= 24) expressResult = NORMAL;

				            if (0 <= fineMotor && fineMotor <= 11) fineMotorResult = DANGEROUS;
				            if (12 <= fineMotor && fineMotor <= 16) fineMotorResult = WARN;
				            if (17 <= fineMotor && fineMotor <= 27) fineMotorResult = NORMAL;

				            if (0 <= bigAction && bigAction <= 16) bigActionResult = DANGEROUS;
				            if (17 <= bigAction && bigAction <= 18) bigActionResult = WARN;
				            if (19 <= bigAction && bigAction <= 28) bigActionResult = NORMAL;

				        } else if (24 * 30 + 16 <= day && day <= 30 * 30 + 15) {
				            if (0 <= cognitive && cognitive <= 20) cognitiveResult = DANGEROUS;
				            if (21 <= cognitive && cognitive <= 24) cognitiveResult = WARN;
				            if (25 <= cognitive && cognitive <= 33) cognitiveResult = NORMAL;

				            if (0 <= understand && understand <= 12)    understandResult = DANGEROUS;
				            if (13 <= understand && understand <= 18) understandResult = WARN;
				            if (19 <= understand && understand <= 24) understandResult = NORMAL;

				            if (0 <= express && express <= 12) expressResult = DANGEROUS;
				            if (13 <= express && express <= 18) expressResult = WARN;
				            if (19 <= express && express <= 24) expressResult = NORMAL;

				            if (0 <= fineMotor && fineMotor <= 14) fineMotorResult = DANGEROUS;
				            if (15 <= fineMotor && fineMotor <= 18) fineMotorResult = WARN;
				            if (19 <= fineMotor && fineMotor <= 27) fineMotorResult = NORMAL;

				            if (0 <= bigAction && bigAction <= 18) bigActionResult = DANGEROUS;
				            if (19 <= bigAction && bigAction <= 21) bigActionResult = WARN;
				            if (22 <= bigAction && bigAction <= 28) bigActionResult = NORMAL;

				        } else if (30 * 30 + 16 <= day && day <= 36 * 30 + 15) {
				            if (0 <= cognitive && cognitive <= 22) cognitiveResult = DANGEROUS;
				            if (23 <= cognitive && cognitive <= 27) cognitiveResult = WARN;
				            if (28 <= cognitive && cognitive <= 33) cognitiveResult = NORMAL;

				            if (0 <= understand && understand <= 12)    understandResult = DANGEROUS;
				            if (13 <= understand && understand <= 20) understandResult = WARN;
				            if (21 <= understand && understand <= 24) understandResult = NORMAL;

				            if (0 <= express && express <= 14) expressResult = DANGEROUS;
				            if (15 <= express && express <= 20) expressResult = WARN;
				            if (21 <= express && express <= 24) expressResult = NORMAL;

				            if (0 <= fineMotor && fineMotor <= 17) fineMotorResult = DANGEROUS;
				            if (18 <= fineMotor && fineMotor <= 22) fineMotorResult = WARN;
				            if (23 <= fineMotor && fineMotor <= 27) fineMotorResult = NORMAL;

				            if (0 <= bigAction && bigAction <= 18) bigActionResult = DANGEROUS;
				            if (19 <= bigAction && bigAction <= 23) bigActionResult = WARN;
				            if (24 <= bigAction && bigAction <= 28) bigActionResult = NORMAL;

				        } else if (36 * 30 + 16 <= day && day <= 42 * 30 + 15) {
				            if (0 <= cognitive && cognitive <= 24) cognitiveResult = DANGEROUS;
				            if (25 <= cognitive && cognitive <= 31) cognitiveResult = WARN;
				            if (32 <= cognitive && cognitive <= 33) cognitiveResult = NORMAL;

				            if (0 <= understand && understand <= 14)    understandResult = DANGEROUS;
				            if (15 <= understand && understand <= 22) understandResult = WARN;
				            if (23 <= understand && understand <= 24) understandResult = NORMAL;

				            if (0 <= express && express <= 15) expressResult = DANGEROUS;
				            if (16 <= express && express <= 23) expressResult = WARN;
				            if (24 == express) expressResult = NORMAL;

				            if (0 <= fineMotor && fineMotor <= 17) fineMotorResult = DANGEROUS;
				            if (18 <= fineMotor && fineMotor <= 25) fineMotorResult = WARN;
				            if (26 <= fineMotor && fineMotor <= 27) fineMotorResult = NORMAL;

				            if (0 <= bigAction && bigAction <= 20) bigActionResult = DANGEROUS;
				            if (21 <= bigAction && bigAction <= 26) bigActionResult = WARN;
				            if (27 <= bigAction && bigAction <= 28) bigActionResult = NORMAL;
				        }

				        records.get(i).put("cognitiveResult", cognitiveResult);
				        records.get(i).put("expressResult", expressResult);
				        records.get(i).put("fineMotorResult", fineMotorResult);
				        records.get(i).put("bigActionResult", bigActionResult);
				        records.get(i).put("understandResult", understandResult);

				        String group ="";
				        if(ageMonth>=1 &&ageMonth<=6){
				        	group = "A";
				        }else if(ageMonth>=7 && ageMonth<=12){
				        	group = "B";
				        }else if(ageMonth>=13 && ageMonth<=24){
				        	group = "C";
				        }else if(ageMonth>=25 && ageMonth<=42){
				        	group = "D";
				        }
				        records.get(i).put("group", group);
					}
				}

				//创建HSSFWorkbook对象
				Workbook wb = new SXSSFWorkbook(100);
				//创建HSSFSheet对象
				Sheet sheet = wb.createSheet("sheet0");
				//创建HSSFRow对象
				Row row = sheet.createRow(0);
				//创建HSSFCell对象
				Cell cell=row.createCell(0);
				//设置单元格的值
				cell.setCellValue("贝利账号");
				cell = row.createCell(1);
				cell.setCellValue("姓名");
				cell = row.createCell(2);
				cell.setCellValue("出生日期");
				cell = row.createCell(3);
				cell.setCellValue("出生体重");
				cell = row.createCell(4);
				cell.setCellValue("纠正胎龄(放的生日)");
				cell = row.createCell(5);
				cell.setCellValue("母亲姓名");
				cell = row.createCell(6);
				cell.setCellValue("母亲生日");
				cell = row.createCell(7);
				cell.setCellValue("母亲身份证后四位");
				cell = row.createCell(8);
				cell.setCellValue("认知能力");
				cell = row.createCell(9);
				cell.setCellValue("语言理解");
				cell = row.createCell(10);
				cell.setCellValue("语言表达");
				cell = row.createCell(11);
				cell.setCellValue("精细动作");
				cell = row.createCell(12);
				cell.setCellValue("大动作");
				cell = row.createCell(13);
				cell.setCellValue("所属社区");
				cell = row.createCell(14);
				cell.setCellValue("问卷日期");
				cell = row.createCell(15);
				cell.setCellValue("孕周");
				cell = row.createCell(16);
				cell.setCellValue("年龄");
				cell = row.createCell(17);
				cell.setCellValue("年龄（月）");
				cell = row.createCell(18);
				cell.setCellValue("分组");

				cell = row.createCell(19);
				cell.setCellValue("认知能力等级");
				cell = row.createCell(20);
				cell.setCellValue("语言理解等级");
				cell = row.createCell(21);
				cell.setCellValue("语言表达等级");
				cell = row.createCell(22);
				cell.setCellValue("精细运动等级");
				cell = row.createCell(23);
				cell.setCellValue("大动作等级");

				cell = row.createCell(24);
				cell.setCellValue("孕周(天)");

				cell = row.createCell(25);
				cell.setCellValue("性别");
				cell = row.createCell(26);
				cell.setCellValue("分娩方式");
				cell = row.createCell(27);
				cell.setCellValue("测试当天身高(cm)");
				cell = row.createCell(28);
				cell.setCellValue("测试当天体重(g)");
				cell = row.createCell(29);
				cell.setCellValue("测试当天头围(cm)");
				cell = row.createCell(30);
				cell.setCellValue("母亲怀孕次数");
				cell = row.createCell(31);
				cell.setCellValue("母亲分娩次数");
				cell = row.createCell(32);
				cell.setCellValue("母亲文化程度");
				cell = row.createCell(33);
				cell.setCellValue("父亲文化程度");

				CellStyle style = wb.createCellStyle();
				style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式

				for (int i = 0; i < records.size(); i++)
				{
					row = sheet.createRow((int) i + 1);
					Map<String,Object> map = records.get(i);
					// 第四步，创建单元格，并设置值
					row.createCell(0).setCellValue(map.get("phoneNum").toString());
					row.createCell(1).setCellValue(map.get("userName").toString());
					row.createCell(2).setCellValue(map.get("birthday").toString());
					row.createCell(3).setCellValue(map.get("birthWeight").toString());
					row.createCell(4).setCellValue(map.get("birthday").toString());
					row.createCell(5).setCellValue("");
					row.createCell(6).setCellValue(map.get("motherBitrhday").toString());
					row.createCell(7).setCellValue(map.get("idiccid").toString());
					row.createCell(8).setCellValue(map.get("cognitive").toString());
					row.createCell(9).setCellValue(map.get("understand").toString());
					row.createCell(10).setCellValue(map.get("express").toString());
					row.createCell(11).setCellValue(map.get("fineMotor").toString());
					row.createCell(12).setCellValue(map.get("bigAction").toString());
					row.createCell(13).setCellValue(map.get("remark").toString());
					row.createCell(14).setCellValue(map.get("testTime").toString());
					row.createCell(15).setCellValue(map.get("pregnancWeek").toString());
					row.createCell(16).setCellValue(map.get("crrectAge").toString());
					row.createCell(17).setCellValue(map.get("ageMonth").toString());
					row.createCell(18).setCellValue(map.get("group").toString());

					row.createCell(19).setCellValue(map.get("cognitiveResult").toString());
					row.createCell(20).setCellValue(map.get("understandResult").toString());
					row.createCell(21).setCellValue(map.get("expressResult").toString());
					row.createCell(22).setCellValue(map.get("fineMotorResult").toString());
					row.createCell(23).setCellValue(map.get("bigActionResult").toString());

					row.createCell(24).setCellValue(map.get("pregnancDay").toString());

					row.createCell(25).setCellValue(map.get("babysex")!=null?map.get("babysex").toString():"未知");
					row.createCell(26).setCellValue(map.get("childbirth")!=null?map.get("childbirth").toString():"未知");
					row.createCell(27).setCellValue(map.get("heightOfDay")!=null?map.get("heightOfDay").toString():"未知");
					row.createCell(28).setCellValue(map.get("weightOfDay")!=null?map.get("weightOfDay").toString():"未知");
					row.createCell(29).setCellValue(map.get("weightOfDay")!=null?map.get("weightOfDay").toString():"未知");
					row.createCell(30).setCellValue(map.get("pregnanciesNum")!=null?map.get("pregnanciesNum").toString():"未知");
					row.createCell(31).setCellValue(map.get("childbirthNum")!=null?map.get("childbirthNum").toString():"未知");
					row.createCell(32).setCellValue(map.get("matherCulture")!=null?map.get("matherCulture").toString():"未知");
					row.createCell(33).setCellValue(map.get("fatherCulture")!=null?map.get("fatherCulture").toString():"未知");

				}

				// 第六步，将文件存到指定位置
				try
				{
					String fileName = "C:\\Users\\Administrator\\Desktop\\upload\\一妇婴贝利档案汇总"+time+".xls";
					OutputStream outputStream = new FileOutputStream(new File(fileName));
					wb.write(outputStream);
					outputStream.close();
					wb.close();
					OperationNote OperationNote = new OperationNote();
					String id = SeqUtil.getSeqNo(Constants.SEQ_NO_FOR_SHUJUDAOCHU);
					OperationNote.setId(id);
					OperationNote.setTalentId((String)mapIn.get("talentId"));
					OperationNote.setDeptId((String)mapIn.get("deptId"));
					OperationNote.setDoctor_id((String)mapIn.get("authorId"));
					OperationNote.setDoctor_name((String)mapIn.get("authorName"));
					OperationNote.setBak1("");
					OperationNote.setBak2("");
					OperationNote.setBak3("");
					OperationNote.setMouth(time);
					OperationNote.setProject_id((String)mapIn.get("projectId"));
					OperationNote.setProject_name((String)mapIn.get("projectName"));
					OperationNote.setQueueId((String)mapIn.get("queueId"));
					OperationNote.setUpdate_time((String)mapIn.get("updateTime"));
					OperationNote.setCreate_time((String)mapIn.get("createTime"));
					if(!StringUtils.isBlank(time) && time.equals(nowDate)) {
						logger.info("当前月份先更新，没有在上传！");
						uploadFile(fileName);
						Map<String,Object> map1 = new HashMap<String,Object>();
						map1.put("projectId", (String)mapIn.get("projectId"));
						map1.put("projectName", (String)mapIn.get("projectName"));
						map1.put("talentId", (String)mapIn.get("talentId"));
						map1.put("mouth", time);
						map1.put("updateTime", (String)mapIn.get("updateTime"));
						int flag = iUploadExcelDAO.updateOperationNote(map1);
						if(flag<=0) {
							Map<String,Object> mapOut = uploadFile(fileName);
							OperationNote.setFile_name((String)mapOut.get("name"));
							OperationNote.setFileurl((String)mapOut.get("url"));
							iUploadExcelDAO.saveOperationNote(OperationNote);
						}
					}else if(!StringUtils.isBlank(time) && !time.equals(nowDate)) {
						Map<String,Object> mapOut = uploadFile(fileName);
						OperationNote.setFile_name((String)mapOut.get("name"));
						OperationNote.setFileurl((String)mapOut.get("url"));
						iUploadExcelDAO.saveOperationNote(OperationNote);
					}
				}
				catch (Exception e)
				{
					e.printStackTrace();
				}

	}

	@Override
	//乐惠评估记录
	public void  queryLehuiAll(Map<String,Object> map) throws Exception{
		Connection connection = null;
    	String url = "jdbc:mysql://rdsap8226j2iuruyoaamgpublic.mysql.rds.aliyuncs.com:3306/bbcare_cloud?createDatabaseIfNotExist=true&amp;amp;useUnicode=true&amp;amp;characterEncoding=utf8mb4&amp;amp;zeroDateTimeBehavior=convertToNull&amp;amp;transformedBitIsBoolean=true";
    	String username = "yunyin";
    	String password = "cl123456";
    	try {
			connection = DriverManager.getConnection(url, username, password);
		} catch (SQLException e) {

			e.printStackTrace();
		}
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");//格式化为年月
    	//开始和结束时间
		String beginTime = (String) map.get("beginTime");
		String endTime = (String) map.get("endTime");
		String sqlAdd = "";
		Map<String,Object> MapIn =  new HashMap<String,Object>(map);
		//计算两个时间中相差的月份
		if(!StringUtils.isBlank(beginTime)) {
			List <String> listMouth = DateUtil.daysBetweenmouth(beginTime,endTime);
			for(int i=0;i<listMouth.size();i++) {
				if(!StringUtils.isBlank(listMouth.get(i))) {
					sqlAdd = " where m.t3createTime>='"+listMouth.get(i)+"-01 00:00:00"+"' and m.t3createTime<='"+listMouth.get(i)+"-31 23:59:59"+"'";
				}
				MapIn.put("mouth", listMouth.get(i));
				logger.info(MapIn);
				List<Map<String, Object>> list = iUploadExcelDAO.selectOperationNote(MapIn);
				if(list!=null&&list.size()>0&&!listMouth.get(i).equals(sdf.format(new Date()))) {
					logger.info("已有导出数据!");
				}else {
					uploadlehui(connection,sqlAdd,listMouth.get(i),sdf.format(new Date()),map);
				}
			}
		}else {
			uploadlehui(connection,sqlAdd,"",sdf.format(new Date()),map);
		}


	}
	private void uploadlehui(Connection connection,String sqlAdd,String time,String nowDate,Map<String,Object> map) throws Exception {
		String sql = "select * from (SELECT t._accountName,b._babyName,b._gender,b._birthday,FLOOR(b.`_pregnancyWeek`/7) AS 孕周,b.`_pregnancyWeek`,a.`_birthLength`,a.`_birthWeight`,\r\n" +
    			"a.`_createTime`,a.`_fatherBirthday`,a.`_fatherEducation`,a.`_fatherProfession`,a.`_motherBirthday`,a.`_motherEducation`,a.`_motherProfession`,\r\n" +
    			"a.`_deliveryMethod`,a.`_pregnantCount`,a.`_city`,a.`_county`,a.`_province`,a.`_hospitalName`,a.`_address` ,  t4._babyQuestionRecord_name  ,\r\n" +
    			"t4._question_name,t4.nsorce ,t4.nnote,t3._createTime as t3createTime,t3._babyAge \r\n" +
    			"FROM t_archives a     \r\n" +
    			"INNER JOIN t_baby b ON a._babyId=b._babyId AND a._code IN(SELECT _code FROM t_wx_content)     \r\n" +
    			"INNER JOIN t_baby_t_account bb ON bb.baby_id=b._babyId    \r\n" +
    			"INNER JOIN t_account t ON bb.account_id=t._accountId    \r\n" +
    			"INNER JOIN     \r\n" +
    			"(SELECT qp._babyId,qp._id FROM t_babyquestionnairepackage qp ) AS t2 ON b._babyId=t2._babyId     \r\n" +
    			"INNER JOIN    \r\n" +
    			"(SELECT qr._babyQuestionnairePackage_id,qr._id,qr._createTime,qr._babyAge FROM t_babyquestionrecord qr ) AS t3 ON t2._id=t3._babyQuestionnairePackage_id      \r\n" +
    			"LEFT JOIN    \r\n" +
    			"(select n._id,n._babyQuestionRecord_id, n._babyQuestionRecord_name,n._sorce as nsorce ,n._note as nnote,n._question_name  from t_babyquestiondetail n where \r\n" +
    			"n._babyQuestionRecord_id in(\r\n" +
    			"select _id from t_babyquestionrecord where _babyQuestionnairePackage_id in(\r\n" +
    			"select _id from t_babyquestionnairepackage where\r\n" +
    			"_babyId in(SELECT _babyId FROM t_archives )) and _status='8'\r\n" +
    			"))AS t4 ON t3._id=t4._babyQuestionRecord_id ) m"+sqlAdd+";";
		Statement statement = connection.createStatement();
		logger.info(sql);
		ResultSet resultSet = statement.executeQuery(sql);
		Workbook workbook = new SXSSFWorkbook(100);
		//HSSFWorkbook workbook = new HSSFWorkbook();
		Sheet sheet = workbook.createSheet();
		Sheet sheet2 = workbook.createSheet("sheet2") ;

		//HSSFSheet sheet = workbook.createSheet();
		//HSSFSheet sheet2 = workbook.createSheet("sheet2") ;

		Row row1 = sheet.createRow(0);
		row1.createCell(0).setCellValue("账号");
		row1.createCell(1).setCellValue("姓名");
		row1.createCell(2).setCellValue("性别");
		row1.createCell(3).setCellValue("宝宝生日");
		row1.createCell(4).setCellValue("分娩孕周（周）");
		row1.createCell(5).setCellValue("分娩孕周（天）");
		row1.createCell(6).setCellValue("出生身长");
		row1.createCell(7).setCellValue("出生体重");
		row1.createCell(8).setCellValue("建档时间");
		row1.createCell(9).setCellValue("父亲生日");
		row1.createCell(10).setCellValue("父亲受教育年限");
		row1.createCell(11).setCellValue("父亲工作");
		row1.createCell(12).setCellValue("母亲生日");
		row1.createCell(13).setCellValue("母亲受教育年限");
		row1.createCell(14).setCellValue("母亲职业");
		row1.createCell(15).setCellValue("分娩方式");
		row1.createCell(16).setCellValue("怀孕次数");
		row1.createCell(17).setCellValue("所在城市");
		row1.createCell(18).setCellValue("地区");
		row1.createCell(19).setCellValue("省");
		row1.createCell(20).setCellValue("就诊医院");
		row1.createCell(21).setCellValue("地址");
		row1.createCell(22).setCellValue("问卷类型");
		row1.createCell(23).setCellValue("题目信息");
		row1.createCell(24).setCellValue("题目得分得分");
		row1.createCell(25).setCellValue("身高（cm）和体重（kg）");
		row1.createCell(26).setCellValue("测试评估日期");

		int count = 1;
		boolean falg = false;
		while (resultSet.next()) {
			//每隔65535条记录后，创建新的sheet
			if (count % 65535== 0) {
				count = 1;
				falg = true;
				Row row2 = sheet2.createRow(0);
				row2.createCell(0).setCellValue("账号");
				row2.createCell(1).setCellValue("姓名");
				row2.createCell(2).setCellValue("性别");
				row2.createCell(3).setCellValue("宝宝生日");
				row2.createCell(4).setCellValue("分娩孕周（周）");
				row2.createCell(5).setCellValue("分娩孕周（天）");
				row2.createCell(6).setCellValue("出生身长");
				row2.createCell(7).setCellValue("出生体重");
				row2.createCell(8).setCellValue("建档时间");
				row2.createCell(9).setCellValue("父亲生日");
				row2.createCell(10).setCellValue("父亲受教育年限");
				row2.createCell(11).setCellValue("父亲工作");
				row2.createCell(12).setCellValue("母亲生日");
				row2.createCell(13).setCellValue("母亲受教育年限");
				row2.createCell(14).setCellValue("母亲职业");
				row2.createCell(15).setCellValue("分娩方式");
				row2.createCell(16).setCellValue("怀孕次数");
				row2.createCell(17).setCellValue("所在城市");
				row2.createCell(18).setCellValue("地区");
				row2.createCell(19).setCellValue("省");
				row2.createCell(20).setCellValue("就诊医院");
				row2.createCell(21).setCellValue("地址");
				row2.createCell(22).setCellValue("问卷类型");
				row2.createCell(23).setCellValue("题目信息");
				row2.createCell(24).setCellValue("题目得分得分");
				row2.createCell(25).setCellValue("身高（cm）和体重（kg）");
				row2.createCell(26).setCellValue("测试评估日期");
			}

		   if (falg) {
			    // 创建工作表
			   Row row = sheet2.createRow(count);
				row.createCell(0).setCellValue(resultSet.getString(1));
				row.createCell(1).setCellValue(resultSet.getString(2));
				if (resultSet.getString(3).equals("N")) {
					row.createCell(2).setCellValue("男");
				}else {
					row.createCell(2).setCellValue("女");
				}
				row.createCell(3).setCellValue(resultSet.getString(4));
				row.createCell(4).setCellValue(resultSet.getString(5));
				row.createCell(5).setCellValue(resultSet.getString(6));
				row.createCell(6).setCellValue(resultSet.getString(7));
				row.createCell(7).setCellValue(resultSet.getString(8));
				row.createCell(8).setCellValue(resultSet.getString(9).substring(0, 10));
				row.createCell(9).setCellValue(resultSet.getString(10));
				row.createCell(10).setCellValue(resultSet.getString(11));
				row.createCell(11).setCellValue(resultSet.getString(12));
				row.createCell(12).setCellValue(resultSet.getString(13));
				row.createCell(13).setCellValue(resultSet.getString(14));
				row.createCell(14).setCellValue(resultSet.getString(15));
				row.createCell(15).setCellValue(resultSet.getString(16));
				row.createCell(16).setCellValue(resultSet.getString(17));
				row.createCell(17).setCellValue(resultSet.getString(18));
				row.createCell(18).setCellValue(resultSet.getString(19));
				row.createCell(19).setCellValue(resultSet.getString(20));
				row.createCell(20).setCellValue(resultSet.getString(21));
				row.createCell(21).setCellValue(resultSet.getString(22));
				row.createCell(22).setCellValue(resultSet.getString(23));
				row.createCell(23).setCellValue(resultSet.getString(24));
				row.createCell(24).setCellValue(resultSet.getString(25));
				row.createCell(25).setCellValue(resultSet.getString(26));
				row.createCell(26).setCellValue(resultSet.getString(27));
				count++;
		   }else {
			   Row row = sheet.createRow(count);
				row.createCell(0).setCellValue(resultSet.getString(1));
				row.createCell(1).setCellValue(resultSet.getString(2));
				if (resultSet.getString(3).equals("N")) {
					row.createCell(2).setCellValue("男");
				}else {
					row.createCell(2).setCellValue("女");
				}
				row.createCell(3).setCellValue(resultSet.getString(4));
				row.createCell(4).setCellValue(resultSet.getString(5));
				row.createCell(5).setCellValue(resultSet.getString(6));
				row.createCell(6).setCellValue(resultSet.getString(7));
				row.createCell(7).setCellValue(resultSet.getString(8));
				row.createCell(8).setCellValue(resultSet.getString(9).substring(0, 10));
				row.createCell(9).setCellValue(resultSet.getString(10));
				row.createCell(10).setCellValue(resultSet.getString(11));
				row.createCell(11).setCellValue(resultSet.getString(12));
				row.createCell(12).setCellValue(resultSet.getString(13));
				row.createCell(13).setCellValue(resultSet.getString(14));
				row.createCell(14).setCellValue(resultSet.getString(15));
				row.createCell(15).setCellValue(resultSet.getString(16));
				row.createCell(16).setCellValue(resultSet.getString(17));
				row.createCell(17).setCellValue(resultSet.getString(18));
				row.createCell(18).setCellValue(resultSet.getString(19));
				row.createCell(19).setCellValue(resultSet.getString(20));
				row.createCell(20).setCellValue(resultSet.getString(21));
				row.createCell(21).setCellValue(resultSet.getString(22));
				row.createCell(22).setCellValue(resultSet.getString(23));
				row.createCell(23).setCellValue(resultSet.getString(24));	//沟通分类
				row.createCell(24).setCellValue(resultSet.getString(25));
				row.createCell(25).setCellValue(resultSet.getString(26));
				row.createCell(26).setCellValue(resultSet.getString(27));
				count++;
		   }

		}

		String fileName = "C:\\Users\\Administrator\\Desktop\\upload\\乐惠问卷"+time+".xls";
		OutputStream outputStream = new FileOutputStream(new File(fileName));
		workbook.write(outputStream);
		workbook.close();
		OperationNote OperationNote = new OperationNote();
		String id = SeqUtil.getSeqNo(Constants.SEQ_NO_FOR_SHUJUDAOCHU);
		OperationNote.setId(id);
		OperationNote.setTalentId((String)map.get("talentId"));
		OperationNote.setDeptId((String)map.get("deptId"));
		OperationNote.setDoctor_id((String)map.get("authorId"));
		OperationNote.setDoctor_name((String)map.get("authorName"));
		OperationNote.setBak1("");
		OperationNote.setBak2("");
		OperationNote.setBak3("");
		OperationNote.setMouth(time);
		OperationNote.setProject_id((String)map.get("projectId"));
		OperationNote.setProject_name((String)map.get("projectName"));
		OperationNote.setQueueId((String)map.get("queueId"));
		OperationNote.setUpdate_time((String)map.get("updateTime"));
		OperationNote.setCreate_time((String)map.get("createTime"));
		if(!StringUtils.isBlank(time) && time.equals(nowDate)) {
			logger.info("当前月份先更新，没有在上传！");
			uploadFile(fileName);
			Map<String,Object> map1 = new HashMap<String,Object>();
			map1.put("projectId", (String)map.get("projectId"));
			map1.put("projectName", (String)map.get("projectName"));
			map1.put("talentId", (String)map.get("talentId"));
			map1.put("mouth", time);
			map1.put("updateTime", (String)map.get("updateTime"));
			int flag = iUploadExcelDAO.updateOperationNote(map1);
			if(flag<=0) {
				Map<String,Object> mapOut = uploadFile(fileName);
				OperationNote.setFile_name((String)mapOut.get("name"));
				OperationNote.setFileurl((String)mapOut.get("url"));
				iUploadExcelDAO.saveOperationNote(OperationNote);
			}
		}else if(!StringUtils.isBlank(time) && !time.equals(nowDate)) {
			Map<String,Object> mapOut = uploadFile(fileName);
			OperationNote.setFile_name((String)mapOut.get("name"));
			OperationNote.setFileurl((String)mapOut.get("url"));
			iUploadExcelDAO.saveOperationNote(OperationNote);
		}
	}

	//上传文件
	public static Map<String,Object> uploadFile (String path) throws Exception {
		File file = new File(path);
		String originalFilename = file.getName();
		String substring = originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase();
		logger.info(substring);
		// Random random = new Random();
		// String name = random.nextInt(10000) + System.currentTimeMillis() + substring;
		String name = originalFilename.substring(0,originalFilename.lastIndexOf("."));
		logger.info(name);
		String imagePath = null;
		InputStream inputStream = null;
		path = "";
		try {
			inputStream = new FileInputStream(file);
			imagePath = OSSClientUtil.uploadToAliyun(path, substring, name, inputStream);
			Map <String,Object> mapOut = new HashMap<String,Object>();
			mapOut.put("url",imagePath);
			mapOut.put("name", originalFilename);
			return mapOut;
		} catch (IOException e) {
			logger.info(e.getMessage());
			throw new Exception("上传文件出错");
		} finally {
			try {
				if (inputStream != null) {
					inputStream.close();
				}
			} catch (IOException e) {
				throw new Exception("上传文件出错");
			}
		}
	}

	//国妇婴抑郁焦虑数据导出
	public void  querAnxious(Map<String,Object> mapIn) throws Exception{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");//格式化为年月
    	//开始和结束时间
		String beginTime = (String) mapIn.get("beginTime");
		String endTime = (String) mapIn.get("endTime");
		//String sqlAdd = "";
		Map<String,Object> MapIn =  new HashMap<String,Object>(mapIn);
		//计算两个时间中相差的月份
		if(!StringUtils.isBlank(beginTime)) {
			List <String> listMouth = DateUtil.daysBetweenmouth(beginTime,endTime);
			for(int i=0;i<listMouth.size();i++) {
				MapIn.put("mouth", listMouth.get(i));
				List<Map<String, Object>> list = iUploadExcelDAO.selectOperationNote(MapIn);
				if(list!=null&&list.size()>0&&!listMouth.get(i).equals(sdf.format(new Date()))) {
					logger.info("已有导出数据!");
				}else {
					queranxious(listMouth.get(i),sdf.format(new Date()),mapIn);
				}
			}
		}else {
			queranxious("",sdf.format(new Date()),mapIn);
		}
	}


	private void queranxious(String time,String nowDate,Map<String,Object> mapIn) throws Exception {
		//创建HSSFWorkbook对象
		Workbook wb = new SXSSFWorkbook(100);
		//创建HSSFSheet对象
		Sheet sheet = wb.createSheet("焦虑数据");
		Sheet sheet0 = wb.createSheet("抑郁数据");
		//导出焦虑数据
		getanxios(sheet, mapIn,time,wb);
		//导出抑郁数据
		getblues(sheet0, mapIn,time,wb);
		// 第六步，将文件存到指定位置
		try
		{
			String fileName = "C:\\Users\\Administrator\\Desktop\\upload\\国妇婴抑郁焦虑"+time+".xls";
			OutputStream outputStream = new FileOutputStream(new File(fileName));
			wb.write(outputStream);
			outputStream.close();
			wb.close();
			OperationNote OperationNote = new OperationNote();
			String id = SeqUtil.getSeqNo(Constants.SEQ_NO_FOR_SHUJUDAOCHU);
			OperationNote.setId(id);
			OperationNote.setTalentId((String)mapIn.get("talentId"));
			OperationNote.setDeptId((String)mapIn.get("deptId"));
			OperationNote.setDoctor_id((String)mapIn.get("authorId"));
			OperationNote.setDoctor_name((String)mapIn.get("authorName"));
			OperationNote.setBak1("");
			OperationNote.setBak2("");
			OperationNote.setBak3("");
			OperationNote.setMouth(time);
			OperationNote.setProject_id((String)mapIn.get("projectId"));
			OperationNote.setProject_name((String)mapIn.get("projectName"));
			OperationNote.setQueueId((String)mapIn.get("queueId"));
			OperationNote.setUpdate_time((String)mapIn.get("updateTime"));
			OperationNote.setCreate_time((String)mapIn.get("createTime"));
			if(!StringUtils.isBlank(time) && time.equals(nowDate)) {
				logger.info("当前月份先更新，没有在上传！");
				Map<String,Object> map1 = new HashMap<String,Object>();
				map1.put("projectId", (String)mapIn.get("projectId"));
				map1.put("projectName", (String)mapIn.get("projectName"));
				map1.put("talentId", (String)mapIn.get("talentId"));
				map1.put("mouth", time);
				map1.put("updateTime", (String)mapIn.get("updateTime"));
				int flag = iUploadExcelDAO.updateOperationNote(map1);
				if(flag<=0) {
					Map<String,Object> mapOut = uploadFile(fileName);
					OperationNote.setFile_name((String)mapOut.get("name"));
					OperationNote.setFileurl((String)mapOut.get("url"));
					iUploadExcelDAO.saveOperationNote(OperationNote);
				}
			}else if(!StringUtils.isBlank(time) && !time.equals(nowDate)) {
				Map<String,Object> mapOut = uploadFile(fileName);
				OperationNote.setFile_name((String)mapOut.get("name"));
				OperationNote.setFileurl((String)mapOut.get("url"));
				iUploadExcelDAO.saveOperationNote(OperationNote);
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	//抑郁数据
	public void getblues(Sheet sheet,Map<String,Object> mapIn,String time,Workbook wb) throws Exception {
		//查询患者 + 记录
			Map<String,Object> paramMap = new HashMap<String,Object>();
			List<String> queueList = new ArrayList<String>();
			String queueId1 ="12chyyjlqueue001";//12SMJD000000001  //12chyyjlqueue001
			String tenantId ="chyyjlta001";//chyyjlta001
			//String deptId="chyyjldept001";
			//String shequ="18862163677";
			queueList.add(queueId1);
			paramMap.put("examinationPaperName","SDS2");
			paramMap.put("queueIdIn",queueList);
			paramMap.put("tenantId",tenantId);
			paramMap.put("beginTime",time+"-01 00:00:00");
			paramMap.put("endTime",time+"-31 23:59:59");
			List<Map<String,Object>> records = followEvaluationDao.selectEvaluationResultAll(paramMap);

			//查询当前抑郁问卷信息
			Map<String, Object> paramMap1 = new HashMap<String, Object>();
			paramMap1.put("field",Constants.FOLLOW_EVALUATION_PREGNANT_KEY);
			paramMap1.put("key",Constants.FOLLOW_EVALUATION_PREGNANT_SDS2);
			FuAssessMentPosition position = followEvaluationDao.selectAssessMentPosition(paramMap1);
			paramMap1 = ToolUtils.typeCast(JSON.parse(position.getValue()));
			JSONArray json = (JSONArray)paramMap1.get("questions");

			//查询患者建档资料
			if(!CollectionUtils.isEmpty(records)){
				for(int i =0 ;i<records.size();i++){
//								String userId = records.get(i).get("userId").toString();
					String ptSchemeId= records.get(i).get("ptSchemeId").toString();
					String queueId = records.get(i).get("queueId").toString();
					String deptId = records.get(i).get("deptId").toString();
			        paramMap.clear();
			        paramMap.put("seqNo", Constants.TASK_SEQ_FOR_INIT);
			        paramMap.put("ptSchemeId",ptSchemeId);
					// 查询taskid
					List<PatientTask> taskList = patientTaskDao.select(paramMap);
					String taskId ="";
					if (!CollectionUtils.isEmpty(taskList)) {
						taskId = taskList.get(0).getId();
					}

					paramMap.clear();
					paramMap.put("tenantId", tenantId);
					paramMap.put("groupType", Constants.TENANT_GROUP_TYPE_FOR_MULCENTER);
					paramMap.put("rootGroupId", deptId);
			        if (null == queueId || "".equals(queueId)) {
			            throw (new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_INPUT_DATA_VERIFY_ERROR, "入参节点错误，未传入队列id或值为空！"));
			        }
			        paramMap.put("taskId", taskId);
			        paramMap.put("queueId", queueId);
			        Map<String, Object> retMap = patientSerivce.qryPatientContentList(paramMap);
//						        logger.info(retMap.get("values").toString());
			        JSONObject questiones =JSONObject.parseObject(JSON.toJSONString(retMap.get("values")));
			        String Pub1100002 = questiones.getString("Pub1100002");
			        String Pub1100004 = questiones.getString("Pub1100004");
			        String Pub1100005 = questiones.getString("Pub1100005");
			        String yunchanfu001 = questiones.getString("yunchanfu001");
			        String yunchanfu002 = questiones.getString("yunchanfu002");
			        String yunchanfu003 = questiones.getString("yunchanfu003");
			        String yunchanfu004 = questiones.getString("yunchanfu004");
			        String yunchanfu005 = questiones.getString("yunchanfu005");

			        records.get(i).put("Pub1100002",Pub1100002);
			        records.get(i).put("Pub1100004",Pub1100004);
			        records.get(i).put("Pub1100005",Pub1100005);
			        records.get(i).put("yunchanfu001",yunchanfu001);
			        records.get(i).put("yunchanfu002",yunchanfu002);
			        records.get(i).put("yunchanfu003",yunchanfu003);
			        records.get(i).put("yunchanfu004",yunchanfu004);
			        records.get(i).put("yunchanfu005",yunchanfu005);

			        if(null == records.get(i).get("testTime")){
				        records.get(i).put("testTime",records.get(i).get("createTime").toString().substring(0,10));
			        }else{
				        records.get(i).put("testTime",records.get(i).get("testTime").toString());
			        }
				}
			}

			//创建HSSFRow对象
			Row row = sheet.createRow(0);
			//创建HSSFCell对象
			Cell cell=row.createCell(0);
			//设置单元格的值
			cell.setCellValue("用户号码");
			cell = row.createCell(1);
			cell.setCellValue("孕妇姓名");
			cell = row.createCell(2);
			cell.setCellValue("孕妇生日");
			cell = row.createCell(3);
			cell.setCellValue("预产期");
			cell = row.createCell(4);
			cell.setCellValue("家族病史");
			cell = row.createCell(5);
			cell.setCellValue("既往病史");
			cell = row.createCell(6);
			cell.setCellValue("是否生产");
			cell = row.createCell(7);
			cell.setCellValue("宝宝姓名");
			cell = row.createCell(8);
			cell.setCellValue("宝宝生日");
			cell = row.createCell(9);
			cell.setCellValue("抑郁得分");
			cell = row.createCell(10);
			cell.setCellValue("抑郁程度");
			for(int i=0;i<json.size();i++) {
				cell = row.createCell(11+i);
				JSONObject josn2 = JSONObject.parseObject(json.get(i).toString());
				cell.setCellValue(josn2.getString("name"));
			}
			CellStyle style = wb.createCellStyle();
			style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式

			for (int i = 0; i < records.size(); i++)
			{
				row = sheet.createRow((int) i + 1);
				Map<String,Object> map = records.get(i);
				// 第四步，创建单元格，并设置值
				row.createCell(0).setCellValue(map.get("phoneNum").toString());
				row.createCell(1).setCellValue(map.get("userName").toString());
				row.createCell(2).setCellValue(map.get("birthday").toString());
				row.createCell(3).setCellValue((String)map.get("Pub1100005"));
				row.createCell(4).setCellValue((String)map.get("yunchanfu001"));
				row.createCell(5).setCellValue((String)map.get("yunchanfu002"));
				row.createCell(6).setCellValue((String)map.get("yunchanfu003"));
				row.createCell(7).setCellValue((String)map.get("yunchanfu004"));
				row.createCell(8).setCellValue((String)map.get("yunchanfu005"));
			    String score = (String)records.get(i).get("score");
		        JSONObject json3 = JSONObject.parseObject(score);
		        row.createCell(9).setCellValue(json3.getIntValue("scoresTotal"));
				row.createCell(10).setCellValue(json3.getString("level"));
				String result = (String)records.get(i).get("result");
		        JSONObject json4 = JSONObject.parseObject(result);
		        paramMap1 = ToolUtils.typeCast(JSON.parse(json4.getString("map")));
		        Map<String, Object> map1 = new TreeMap<String, Object>(
		                new Comparator<String>() {
		                    public int compare(String obj1, String obj2) {
		                        // 升序排序
		                        return obj1.compareTo(obj2);
		                    }
		                });
		        map1.putAll(paramMap1);
		        int j = 1;
		        for (String in : map1.keySet()) {
		        	 //map.keySet()返回的是所有key的值
		        	String str = "";
		        	if("10".equals(in)) {
		        		str = (String) map1.get(in);//得到每个key多对用value的值
		        		row.createCell(10+j).setCellValue(str.toString());
		        	}else {
		        		str = (String) map1.get(in);
		        		if("0".equals(str)) {
		        			str = "沒有";
		        		}else if("1".equals(str)) {
		        			str = "有几天";
		        		}else if("2".equals(str)) {
		        			str = "一半以上时间";
		        		}else if("3".equals(str)) {
		        			str = "几乎天天";
		        		}
		        		row.createCell(10+j).setCellValue(str.toString());
		        	}
		        	j++;
		        }
			}
	}

	public void getanxios(Sheet sheet,Map<String,Object> mapIn,String time,Workbook wb) throws Exception {
		//查询患者 + 记录
			Map<String,Object> paramMap = new HashMap<String,Object>();
			List<String> queueList = new ArrayList<String>();
			String queueId1 ="12chyyjlqueue001";//12SMJD000000001  //12chyyjlqueue001
			String tenantId ="chyyjlta001";//chyyjlta001
			//String deptId="chyyjldept001";
			//String shequ="18862163677";
			queueList.add(queueId1);
			paramMap.put("examinationPaperName","SAS2");
			paramMap.put("queueIdIn",queueList);
			paramMap.put("tenantId",tenantId);
			paramMap.put("beginTime",time+"-01 00:00:00");
			paramMap.put("endTime",time+"-31 23:59:59");
			List<Map<String,Object>> records = followEvaluationDao.selectEvaluationResultAll(paramMap);

			//查询当前抑郁问卷信息
			Map<String, Object> paramMap1 = new HashMap<String, Object>();
			paramMap1.put("field",Constants.FOLLOW_EVALUATION_PREGNANT_KEY);
			paramMap1.put("key",Constants.FOLLOW_EVALUATION_PREGNANT_SAS2);
			FuAssessMentPosition position = followEvaluationDao.selectAssessMentPosition(paramMap1);
			paramMap1 = ToolUtils.typeCast(JSON.parse(position.getValue()));
			JSONArray json = (JSONArray) paramMap1.get("questions");

			//查询患者建档资料
			if(!CollectionUtils.isEmpty(records)){
				for(int i =0 ;i<records.size();i++){
//								String userId = records.get(i).get("userId").toString();
					String ptSchemeId= records.get(i).get("ptSchemeId").toString();
					String queueId = records.get(i).get("queueId").toString();
					String deptId = records.get(i).get("deptId").toString();
			        paramMap.clear();
			        paramMap.put("seqNo", Constants.TASK_SEQ_FOR_INIT);
			        paramMap.put("ptSchemeId",ptSchemeId);
					// 查询taskid
					List<PatientTask> taskList = patientTaskDao.select(paramMap);
					String taskId ="";
					if (!CollectionUtils.isEmpty(taskList)) {
						taskId = taskList.get(0).getId();
					}

					paramMap.clear();
					paramMap.put("tenantId", tenantId);
					paramMap.put("groupType", Constants.TENANT_GROUP_TYPE_FOR_MULCENTER);
					paramMap.put("rootGroupId", deptId);
			        if (null == queueId || "".equals(queueId)) {
			            throw (new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_INPUT_DATA_VERIFY_ERROR, "入参节点错误，未传入队列id或值为空！"));
			        }
			        paramMap.put("taskId", taskId);
			        paramMap.put("queueId", queueId);
			        Map<String, Object> retMap = patientSerivce.qryPatientContentList(paramMap);
//						        logger.info(retMap.get("values").toString());
			        JSONObject questiones =JSONObject.parseObject(JSON.toJSONString(retMap.get("values")));
			        String Pub1100002 = questiones.getString("Pub1100002");
			        String Pub1100004 = questiones.getString("Pub1100004");
			        String Pub1100005 = questiones.getString("Pub1100005");
			        String yunchanfu001 = questiones.getString("yunchanfu001");
			        String yunchanfu002 = questiones.getString("yunchanfu002");
			        String yunchanfu003 = questiones.getString("yunchanfu003");
			        String yunchanfu004 = questiones.getString("yunchanfu004");
			        String yunchanfu005 = questiones.getString("yunchanfu005");

			        records.get(i).put("Pub1100002",Pub1100002);
			        records.get(i).put("Pub1100004",Pub1100004);
			        records.get(i).put("Pub1100005",Pub1100005);
			        records.get(i).put("yunchanfu001",yunchanfu001);
			        records.get(i).put("yunchanfu002",yunchanfu002);
			        records.get(i).put("yunchanfu003",yunchanfu003);
			        records.get(i).put("yunchanfu004",yunchanfu004);
			        records.get(i).put("yunchanfu005",yunchanfu005);

			        if(null == records.get(i).get("testTime")){
				        records.get(i).put("testTime",records.get(i).get("createTime").toString().substring(0,10));
			        }else{
				        records.get(i).put("testTime",records.get(i).get("testTime").toString());
			        }
				}
			}

			//创建HSSFRow对象
			Row row = sheet.createRow(0);
			//创建HSSFCell对象
			Cell cell=row.createCell(0);
			//设置单元格的值
			cell.setCellValue("用户号码");
			cell = row.createCell(1);
			cell.setCellValue("孕妇姓名");
			cell = row.createCell(2);
			cell.setCellValue("孕妇生日");
			cell = row.createCell(3);
			cell.setCellValue("预产期");
			cell = row.createCell(4);
			cell.setCellValue("家族病史");
			cell = row.createCell(5);
			cell.setCellValue("既往病史");
			cell = row.createCell(6);
			cell.setCellValue("是否生产");
			cell = row.createCell(7);
			cell.setCellValue("宝宝姓名");
			cell = row.createCell(8);
			cell.setCellValue("宝宝生日");
			cell = row.createCell(9);
			cell.setCellValue("焦虑得分");
			cell = row.createCell(10);
			cell.setCellValue("焦虑程度");
			for(int i=0;i<json.size();i++) {
				cell = row.createCell(11+i);
				JSONObject josn2 = JSONObject.parseObject(json.get(i).toString());
				cell.setCellValue(josn2.getString("name"));
			}
			CellStyle style = wb.createCellStyle();
			style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式

			for (int i = 0; i < records.size(); i++)
			{
				row = sheet.createRow((int) i + 1);
				Map<String,Object> map = records.get(i);
				// 第四步，创建单元格，并设置值
				row.createCell(0).setCellValue(map.get("phoneNum").toString());
				row.createCell(1).setCellValue(map.get("userName").toString());
				row.createCell(2).setCellValue(map.get("birthday").toString());
				row.createCell(3).setCellValue((String)map.get("Pub1100005"));
				row.createCell(4).setCellValue((String)map.get("yunchanfu001"));
				row.createCell(5).setCellValue((String)map.get("yunchanfu002"));
				row.createCell(6).setCellValue((String)map.get("yunchanfu003"));
				row.createCell(7).setCellValue((String)map.get("yunchanfu004"));
				row.createCell(8).setCellValue((String)map.get("yunchanfu005"));

				String score = (String)records.get(i).get("score");
		        JSONObject json3 = JSONObject.parseObject(score);
		        row.createCell(9).setCellValue(json3.getIntValue("scoresTotal"));
				row.createCell(10).setCellValue(json3.getString("level"));
				String result = (String)records.get(i).get("result");
		        JSONObject json4 = JSONObject.parseObject(result);
		        paramMap1 = ToolUtils.typeCast(JSON.parse(json4.getString("map")));
		        Map<String, Object> map1 = new TreeMap<String, Object>(
		                new Comparator<String>() {
		                    public int compare(String obj1, String obj2) {
		                        // 升序排序
		                        return obj1.compareTo(obj2);
		                    }
		                });
		        map1.putAll(paramMap1);
		        int j = 1;
		        for (String in : map1.keySet()) {
		        	 //map.keySet()返回的是所有key的值
		        	String str = "";
		        	if("8".equals(in)) {
		        		str = (String) map1.get(in);//得到每个key多对用value的值
		        		row.createCell(10+j).setCellValue(str.toString());
		        	}else {
		        		str = (String) map1.get(in);
		        		if("0".equals(str)) {
		        			str = "沒有";
		        		}else if("1".equals(str)) {
		        			str = "有几天";
		        		}else if("2".equals(str)) {
		        			str = "一半以上时间";
		        		}else if("3".equals(str)) {
		        			str = "几乎天天";
		        		}
		        		row.createCell(10+j).setCellValue(str.toString());
		        	}
		        	j++;
		        }
			}
	}

	//国妇婴儿保主诉数据导出
	public void  queryCareBaby(Map<String,Object> mapIn) throws Exception{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");//格式化为年月
    	//开始和结束时间
		String beginTime = (String) mapIn.get("beginTime");
		String endTime = (String) mapIn.get("endTime");
		//String sqlAdd = "";
		Map<String,Object> MapIn =  new HashMap<String,Object>(mapIn);
		//计算两个时间中相差的月份
		if(!StringUtils.isBlank(beginTime)) {
			List <String> listMouth = DateUtil.daysBetweenmouth(beginTime,endTime);
			for(int i=0;i<listMouth.size();i++) {
				MapIn.put("mouth", listMouth.get(i));
				List<Map<String, Object>> list = iUploadExcelDAO.selectOperationNote(MapIn);
				if(list!=null&&list.size()>0&&!listMouth.get(i).equals(sdf.format(new Date()))) {
					logger.info("已有导出数据!");
				}else {
					querycarebaby(listMouth.get(i),sdf.format(new Date()),mapIn);
				}
			}
		}else {
			querycarebaby("",sdf.format(new Date()),mapIn);
		}
	}

	//儿保主诉数据导出
	private void querycarebaby(String time,String nowDate,Map<String,Object> mapIn) throws Exception {

		//创建HSSFWorkbook对象
		Workbook workbook = new SXSSFWorkbook(100);
		//创建HSSFSheet对象
		Sheet sheet = workbook.createSheet("主诉资料");
		//查询患者 + 记录
		Map<String,Object> paramMap = new HashMap<String,Object>();
		//List<String> queueList = new ArrayList<String>();
		String queueId ="12YJZQZ949Eb44iksv5g";
		String tenantId ="shgjhpfyb01";//shgjhpfyb01 正式需要替换
		//String deptId = "ayddept001";//shgjhpfybj10001 正式需要替换
		String taskType = "2";
		paramMap.put("queueId",queueId);
		paramMap.put("tenantId",tenantId);
		paramMap.put("taskType",taskType);
		List<Map<String,Object>> records = new ArrayList<Map<String,Object>>();
		records = PatientContentDao.selectPtTaskInfo(paramMap);

		//创建HSSFRow对象
		Row row = sheet.createRow(0);
		//创建HSSFCell对象
		Cell cell=row.createCell(0);
		//设置单元格的值
		cell.setCellValue("用户号码");
		cell = row.createCell(1);
		cell.setCellValue("姓名");
		cell = row.createCell(2);
		cell.setCellValue("出生日期");
		cell = row.createCell(3);
		cell.setCellValue("预产期");
		cell = row.createCell(4);
		cell.setCellValue("孕周");
		cell = row.createCell(5);
		cell.setCellValue("母亲姓名");
		cell = row.createCell(6);
		cell.setCellValue("母亲职业");
		cell = row.createCell(7);
		cell.setCellValue("母亲文化程度");
		cell = row.createCell(8);
		cell.setCellValue("父亲姓名");
		cell = row.createCell(9);
		cell.setCellValue("父亲职业");
		cell = row.createCell(10);
		cell.setCellValue("父亲文化程度");
		cell = row.createCell(11);
		cell.setCellValue("是否是高危儿");
		cell = row.createCell(12);
		cell.setCellValue("高危儿原因");
		cell = row.createCell(13);
		cell.setCellValue("胎次");
		cell = row.createCell(14);
		cell.setCellValue("产次");
		cell = row.createCell(15);
		cell.setCellValue("分娩孕周");
		cell = row.createCell(16);
		cell.setCellValue("生产方式");
		cell = row.createCell(17);
		cell.setCellValue("出生时体重");
		cell = row.createCell(18);
		cell.setCellValue("出生时情况");
		cell = row.createCell(19);
		cell.setCellValue("Apgar评分");
		cell = row.createCell(20);
		cell.setCellValue("母孕期情况");
		cell = row.createCell(21);
		cell.setCellValue("受孕情况");
		cell = row.createCell(22);
		cell.setCellValue("主诉");
		cell = row.createCell(23);
		cell.setCellValue("喂养方式");
		cell = row.createCell(24);
		cell.setCellValue("乳品种类");
		cell = row.createCell(25);
		cell.setCellValue("喂养次数");
		cell = row.createCell(26);
		cell.setCellValue("喂养量");
		cell = row.createCell(27);
		cell.setCellValue("断奶时间");
		cell = row.createCell(28);
		cell.setCellValue("添加辅食品的时间(月龄)");
		cell = row.createCell(29);
		cell.setCellValue("添加辅食种类");
		cell = row.createCell(30);
		cell.setCellValue("有无喂养困难");
		cell = row.createCell(31);
		cell.setCellValue("大便情况");
		cell = row.createCell(32);
		cell.setCellValue("便质");
		cell = row.createCell(33);
		cell.setCellValue("是否有药物过敏史");
		cell = row.createCell(34);
		cell.setCellValue("过敏药物");
		cell = row.createCell(35);
		cell.setCellValue("是否有食物过敏史");
		cell = row.createCell(36);
		cell.setCellValue("过敏食物");
		cell = row.createCell(37);
		cell.setCellValue("是否有预防接种史");
		cell = row.createCell(38);
		cell.setCellValue("接种反应");
		cell = row.createCell(39);
		cell.setCellValue("是否有家族性或遗传性疾病史及传染病史");
		cell = row.createCell(40);
		cell.setCellValue("传染病");
		cell = row.createCell(41);
		cell.setCellValue("填写日期");
		CellStyle style = workbook.createCellStyle();
		style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式

		//查询患者建档资料
		int count=1;//行数
		if(!CollectionUtils.isEmpty(records)){
			for(int i =0 ;i<records.size();i++){
		        paramMap.clear();
		        paramMap.put("seqNo", Constants.TASK_SEQ_FOR_INIT);
		        paramMap.put("taskId",records.get(i).get("taskId"));
		        paramMap.put("beginTime",time+"-01 00:00:00");
				paramMap.put("endTime",time+"-31 23:59:59");
				paramMap.put("contDataTemplType","8");
				paramMap.put("groupByAccept","true");
				List<PatientContentData> lists = PatientContentDao.selectContentDataByTaskIdOr(paramMap);
				if(lists==null || lists.size()<=0) {
					continue;
				}else {
					for(int j=0;j<lists.size();j++) {
						paramMap.remove("groupByAccept");
						paramMap.put("updateAccept",lists.get(j).getUpdateAccept());
						List<PatientContentData> list = PatientContentDao.selectContentDataByTaskIdOr(paramMap);
						Map<String,Object> mapout = new HashMap<String,Object>();
						row = sheet.createRow(count);
						row.createCell(41).setCellValue(list.get(j).getCreateTime());
						for(int t=0;t<list.size();t++) {
							mapout.put(list.get(t).getQuestionId(), list.get(t).getQuestionAnswer());
						}
						row.createCell(0).setCellValue((String)records.get(i).get("phoneNo"));
						row.createCell(1).setCellValue((String)records.get(i).get("userName"));
						row.createCell(2).setCellValue(records.get(i).get("birthday").toString());
						row.createCell(3).setCellValue((String)records.get(i).get("expectedDay").toString());
						row.createCell(4).setCellValue((String)records.get(i).get("pregnancyDay").toString());
						row.createCell(5).setCellValue((String)mapout.get("X1010101"));
						row.createCell(6).setCellValue((String)mapout.get("X1010102"));
						row.createCell(7).setCellValue((String)mapout.get("X1010103"));
						row.createCell(8).setCellValue((String)mapout.get("X1010104"));
						row.createCell(9).setCellValue((String)mapout.get("X1010105"));
						row.createCell(10).setCellValue((String)mapout.get("X1010106"));
						row.createCell(11).setCellValue((String)mapout.get("X1010128"));
						row.createCell(12).setCellValue((String)mapout.get("X1010129"));
						row.createCell(13).setCellValue((String)mapout.get("X1010130"));
						row.createCell(14).setCellValue((String)mapout.get("X1010131"));
						row.createCell(15).setCellValue((String)mapout.get("X1010132"));
						row.createCell(16).setCellValue((String)mapout.get("X1010133"));
						row.createCell(17).setCellValue((String)mapout.get("X1010134"));
						row.createCell(18).setCellValue((String)mapout.get("X1010135"));
						row.createCell(19).setCellValue((String)mapout.get("X1010136"));
						row.createCell(20).setCellValue((String)mapout.get("X1010137"));
						row.createCell(21).setCellValue((String)mapout.get("X1010138"));
						row.createCell(22).setCellValue((String)mapout.get("X1010139"));
						row.createCell(23).setCellValue((String)mapout.get("X1010107"));
						row.createCell(24).setCellValue((String)mapout.get("X1010108"));
						row.createCell(25).setCellValue((String)mapout.get("X1010109"));
						row.createCell(26).setCellValue((String)mapout.get("X1010110"));
						row.createCell(27).setCellValue((String)mapout.get("X1010111"));
						row.createCell(28).setCellValue((String)mapout.get("X1010112"));
						row.createCell(29).setCellValue((String)mapout.get("X1010113"));
						row.createCell(30).setCellValue((String)mapout.get("X1010124"));
						row.createCell(31).setCellValue((String)mapout.get("X1010114"));
						row.createCell(32).setCellValue((String)mapout.get("X1010115"));
						row.createCell(33).setCellValue((String)mapout.get("X1010116"));
						row.createCell(34).setCellValue((String)mapout.get("X1010117"));
						row.createCell(35).setCellValue((String)mapout.get("X1010118"));
						row.createCell(36).setCellValue((String)mapout.get("X1010119"));
						row.createCell(37).setCellValue((String)mapout.get("X1010120"));
						row.createCell(38).setCellValue((String)mapout.get("X1010121"));
						row.createCell(39).setCellValue((String)mapout.get("X1010122"));
						row.createCell(40).setCellValue((String)mapout.get("X1010123"));
						count++;
					}
				}

			}
		}

		String fileName = "C:\\Users\\Administrator\\Desktop\\upload\\主诉"+time+".xls";
		OutputStream outputStream = new FileOutputStream(new File(fileName));
		workbook.write(outputStream);
		workbook.close();
		OperationNote OperationNote = new OperationNote();
		String id = SeqUtil.getSeqNo(Constants.SEQ_NO_FOR_SHUJUDAOCHU);
		OperationNote.setId(id);
		OperationNote.setTalentId((String)mapIn.get("talentId"));
		OperationNote.setDeptId((String)mapIn.get("deptId"));
		OperationNote.setDoctor_id((String)mapIn.get("authorId"));
		OperationNote.setDoctor_name((String)mapIn.get("authorName"));
		OperationNote.setBak1("");
		OperationNote.setBak2("");
		OperationNote.setBak3("");
		OperationNote.setMouth(time);
		OperationNote.setProject_id((String)mapIn.get("projectId"));
		OperationNote.setProject_name((String)mapIn.get("projectName"));
		OperationNote.setQueueId((String)mapIn.get("queueId"));
		OperationNote.setUpdate_time((String)mapIn.get("updateTime"));
		OperationNote.setCreate_time((String)mapIn.get("createTime"));
		if(!StringUtils.isBlank(time) && time.equals(nowDate)) {
			logger.info("当前月份先更新，没有在上传！");
			Map<String,Object> map2 = new HashMap<String,Object>();
			map2.put("projectId", (String)mapIn.get("projectId"));
			map2.put("projectName", (String)mapIn.get("projectName"));
			map2.put("talentId", (String)mapIn.get("talentId"));
			map2.put("mouth", time);
			map2.put("updateTime", (String)mapIn.get("updateTime"));
			int flag = iUploadExcelDAO.updateOperationNote(map2);
			if(flag<=0) {
				Map<String,Object> mapOut = uploadFile(fileName);
				OperationNote.setFile_name((String)mapOut.get("name"));
				OperationNote.setFileurl((String)mapOut.get("url"));
				iUploadExcelDAO.saveOperationNote(OperationNote);
			}
		}else if(!StringUtils.isBlank(time) && !time.equals(nowDate)) {
			Map<String,Object> mapOut = uploadFile(fileName);
			OperationNote.setFile_name((String)mapOut.get("name"));
			OperationNote.setFileurl((String)mapOut.get("url"));
			iUploadExcelDAO.saveOperationNote(OperationNote);
		}
}


	//国妇婴抑郁焦虑数据导出
	public void  queryLCZS(Map<String,Object> mapIn) throws Exception{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");//格式化为年月
    	//开始和结束时间
		String beginTime = (String) mapIn.get("beginTime");
		String endTime = (String) mapIn.get("endTime");
		//String sqlAdd = "";
		Map<String,Object> MapIn =  new HashMap<String,Object>(mapIn);
		//计算两个时间中相差的月份
		if(!StringUtils.isBlank(beginTime)) {
			List <String> listMouth = DateUtil.daysBetweenmouth(beginTime,endTime);
			for(int i=0;i<listMouth.size();i++) {
				MapIn.put("mouth", listMouth.get(i));
				List<Map<String, Object>> list = iUploadExcelDAO.selectOperationNote(MapIn);
				if(list!=null&&list.size()>0&&!listMouth.get(i).equals(sdf.format(new Date()))) {
					logger.info("已有导出数据!");
				}else {
					querylczs(listMouth.get(i),sdf.format(new Date()),mapIn);
				}
			}
		}else {
			querylczs("",sdf.format(new Date()),mapIn);
		}
	}

	private void querylczs(String time,String nowDate,Map<String,Object> mapIn) throws Exception {
		//创建HSSFWorkbook对象
		Workbook wb = new SXSSFWorkbook(100);
		//创建HSSFSheet对象
		Sheet sheet = wb.createSheet("基础问卷");
		Sheet sheet0 = wb.createSheet("职业紧张压力问卷");
		Sheet sheet1 = wb.createSheet("生活事件量表");
		//基本数据
		getGLE(sheet, mapIn,time,wb);
		//职业紧张压力问卷
		getOSI(sheet0, mapIn,time,wb);
		//生活事件量表
		getLES(sheet1, mapIn,time,wb);
		// 第六步，将文件存到指定位置
		try
		{
			String fileName = "C:\\Users\\Administrator\\Desktop\\upload\\国妇婴卵巢早衰"+time+".xls";
			OutputStream outputStream = new FileOutputStream(new File(fileName));
			wb.write(outputStream);
			outputStream.close();
			wb.close();
			OperationNote OperationNote = new OperationNote();
			String id = SeqUtil.getSeqNo(Constants.SEQ_NO_FOR_SHUJUDAOCHU);
			OperationNote.setId(id);
			OperationNote.setTalentId((String)mapIn.get("talentId"));
			OperationNote.setDeptId((String)mapIn.get("deptId"));
			OperationNote.setDoctor_id((String)mapIn.get("authorId"));
			OperationNote.setDoctor_name((String)mapIn.get("authorName"));
			OperationNote.setBak1("");
			OperationNote.setBak2("");
			OperationNote.setBak3("");
			OperationNote.setMouth(time);
			OperationNote.setProject_id((String)mapIn.get("projectId"));
			OperationNote.setProject_name((String)mapIn.get("projectName"));
			OperationNote.setQueueId((String)mapIn.get("queueId"));
			OperationNote.setUpdate_time((String)mapIn.get("updateTime"));
			OperationNote.setCreate_time((String)mapIn.get("createTime"));
			if(!StringUtils.isBlank(time) && time.equals(nowDate)) {
				logger.info("当前月份先更新，没有在上传！");
				Map<String,Object> map1 = new HashMap<String,Object>();
				map1.put("projectId", (String)mapIn.get("projectId"));
				map1.put("projectName", (String)mapIn.get("projectName"));
				map1.put("talentId", (String)mapIn.get("talentId"));
				map1.put("mouth", time);
				map1.put("updateTime", (String)mapIn.get("updateTime"));
				int flag = iUploadExcelDAO.updateOperationNote(map1);
				if(flag<=0) {
					Map<String,Object> mapOut = uploadFile(fileName);
					OperationNote.setFile_name((String)mapOut.get("name"));
					OperationNote.setFileurl((String)mapOut.get("url"));
					iUploadExcelDAO.saveOperationNote(OperationNote);
				}
			}else if(!StringUtils.isBlank(time) && !time.equals(nowDate)) {
				Map<String,Object> mapOut = uploadFile(fileName);
				OperationNote.setFile_name((String)mapOut.get("name"));
				OperationNote.setFileurl((String)mapOut.get("url"));
				iUploadExcelDAO.saveOperationNote(OperationNote);
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	//职业紧张压力问卷
	public void getLES(Sheet sheet,Map<String,Object> mapIn,String time,Workbook wb) throws Exception {
		//查询患者 + 记录
		Map<String,Object> paramMap = new HashMap<String,Object>();
		List<String> queueList = new ArrayList<String>();
		String queueId1 ="12lczsqueue001";//12SMJD000000001  //12chyyjlqueue001
		String tenantId ="lczsta001";//lczsta001
		//String deptId="chyyjldept001";
		//String shequ="18862163677";
		queueList.add(queueId1);
		paramMap.put("examinationPaperName","LES");
		paramMap.put("queueIdIn",queueList);
		paramMap.put("tenantId",tenantId);
		paramMap.put("beginTime",time+"-01 00:00:00");
		paramMap.put("endTime",time+"-31 23:59:59");
		List<Map<String,Object>> records = followEvaluationDao.selectEvaluationResultAll(paramMap);

		//查询当前抑郁问卷信息
		Map<String, Object> paramMap1 = new HashMap<String, Object>();
		paramMap1.put("field",Constants.FOLLOW_EVALUATION_PREGNANT_KEY);
		paramMap1.put("key",Constants.FOLLOW_EVALUATION_PREGNANT_LES);
		FuAssessMentPosition position = followEvaluationDao.selectAssessMentPosition(paramMap1);
		paramMap1 = ToolUtils.typeCast(JSON.parse(position.getValue()));
		JSONArray json = (JSONArray)paramMap1.get("生活事件量表");
		//查询患者建档资料
		if(!CollectionUtils.isEmpty(records)){
			for(int i =0 ;i<records.size();i++){
//					String userId = records.get(i).get("userId").toString();
				String ptSchemeId= records.get(i).get("ptSchemeId").toString();
				String queueId = records.get(i).get("queueId").toString();
				String deptId = records.get(i).get("deptId").toString();
		        paramMap.clear();
		        paramMap.put("seqNo", Constants.TASK_SEQ_FOR_INIT);
		        paramMap.put("ptSchemeId",ptSchemeId);
				// 查询taskid
				List<PatientTask> taskList = patientTaskDao.select(paramMap);
				String taskId ="";
				if (!CollectionUtils.isEmpty(taskList)) {
					taskId = taskList.get(0).getId();
				}

				paramMap.clear();
				paramMap.put("tenantId", tenantId);
				paramMap.put("groupType", Constants.TENANT_GROUP_TYPE_FOR_MULCENTER);
				paramMap.put("rootGroupId", deptId);
		        if (null == queueId || "".equals(queueId)) {
		            throw (new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_INPUT_DATA_VERIFY_ERROR, "入参节点错误，未传入队列id或值为空！"));
		        }
		        paramMap.put("taskId", taskId);
		        paramMap.put("queueId", queueId);
		        Map<String, Object> retMap = patientSerivce.qryPatientContentList(paramMap);
//						        logger.info(retMap.get("values").toString());
		        JSONObject questiones =JSONObject.parseObject(JSON.toJSONString(retMap.get("values")));
		        String Pub1100002 = questiones.getString("Pub1100002");
		        String Pub1100004 = questiones.getString("Pub1100004");
		        String Pub1100005 = questiones.getString("Pub1100005");

		        records.get(i).put("Pub1100002",Pub1100002);
		        records.get(i).put("Pub1100004",Pub1100004);
		        records.get(i).put("Pub1100005",Pub1100005);

		        if(null == records.get(i).get("testTime")){
			        records.get(i).put("testTime",records.get(i).get("createTime").toString().substring(0,10));
		        }else{
			        records.get(i).put("testTime",records.get(i).get("testTime").toString());
		        }
			}
		}

		//创建HSSFRow对象
		Row row = sheet.createRow(0);
		//创建HSSFCell对象
		Cell cell=row.createCell(0);
		//设置单元格的值
		cell.setCellValue("用户号码");
		cell = row.createCell(1);
		cell.setCellValue("姓名");
		cell = row.createCell(2);
		cell.setCellValue("出生日期");
		cell = row.createCell(3);
		cell.setCellValue("预产期");
		cell = row.createCell(4);
		cell.setCellValue("正性事件得分");
		cell = row.createCell(5);
		cell.setCellValue("负性事件得分");
		cell = row.createCell(6);
		cell.setCellValue("总分");
		int count =7;//列数
		List<Object> list1 = null;
		List<Object> list2 = new ArrayList<Object>();
		for(int i=0;i<json.size();i++) {
			JSONObject josn2 = JSONObject.parseObject(json.get(i).toString());
			JSONArray josn3 = josn2.getJSONArray("questions");
			for(int j=0;j<josn3.size();j++) {
				JSONArray josn4 = josn3.getJSONObject(j).getJSONArray("questions");
				String id = (String) josn3.getJSONObject(j).get("id");
				//是否list
				if(josn4!=null&&josn4.size()>0) {
					for(int s =0;s<josn4.size();s++) {
						Map<String,Object> map = new HashMap<String,Object>();
						//取出问题题目
						Object obj = josn4.getJSONObject(s).get("name");
						map.put("id", id+"."+josn4.getJSONObject(s).get("id"));
						map.put("option", josn4.getJSONObject(s).get("option"));
						if(obj==null) {
							continue;
						}else {
							if(obj instanceof List) {
								list1 = ToolUtils.typeCast(obj);
								map.put("count", count);
								cell = row.createCell(count);
								String ut ="";
								for(Object obj2 :list1) {
									if(obj2.equals("text")||obj2.equals("text-num")||obj2.equals("text-boxes")||obj2.equals("text-time")||obj2.equals("text-date")) {
										ut = ut+"_____";
									}else {
										ut = ut+obj2;
									}
								}
								cell.setCellValue(ut);
								count++;
							}else {
								cell = row.createCell(count);
								map.put("count", count);
								cell.setCellValue((String)obj);
								count++;
							}

						}
						list2.add(map);
					}
				}
			}
		}
		CellStyle style = wb.createCellStyle();
		style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式

		for (int i = 0; i < records.size(); i++)
		{
			row = sheet.createRow((int) i + 1);
			Map<String,Object> map = records.get(i);
			// 第四步，创建单元格，并设置值
			row.createCell(0).setCellValue(map.get("phoneNum").toString());
			row.createCell(1).setCellValue(map.get("userName").toString());
			try {
				row.createCell(2).setCellValue(map.get("birthday").toString());
			} catch (Exception e) {
				row.createCell(2).setCellValue((String)map.get("birthday"));
			}
			row.createCell(3).setCellValue((String)map.get("Pub1100005"));
		    String score = (String)records.get(i).get("score");
	        JSONObject json3 = JSONObject.parseObject(score);
	        row.createCell(4).setCellValue(json3.getIntValue("scoreMain"));
			row.createCell(5).setCellValue(json3.getIntValue("scoreLoss"));
			row.createCell(6).setCellValue(json3.getIntValue("scoreTitle"));
			String result = (String)records.get(i).get("result");
	        JSONObject json4 = JSONObject.parseObject(result);
	        paramMap1 = ToolUtils.typeCast(JSON.parse(json4.getString("ques")));
	        for (String in : paramMap1.keySet()) {
	        	 //map.keySet()返回的是所有key的值
	        	List<String> list = new ArrayList<String>();
	        	String str2="";
	        	try {
	        		list  = ToolUtils.typeCast(paramMap1.get(in));
				} catch (Exception e) {
					str2  = (String)paramMap1.get(in);
				}
	        	for(int j1 = 0;j1<list2.size();j1++) {
	        		Map<String,Object> map1 =  ToolUtils.typeCast(list2.get(j1));
	        		String str ="";
	        		if(in.equals(map1.get("id"))) {
	        			if(map1.get("option")!=null&&map1.get("option")!="") {
	        				JSONObject json5 = ToolUtils.typeCast(map1.get("option"));
	        				str = json5.getString((String)paramMap1.get(in));
	        				int count1 = (int) map1.get("count");
	        				row.createCell(count1).setCellValue(str);
	        			}else {
	        				int count1 = (int) map1.get("count");
	        				if(!StringUtils.isBlank(str2)) {
	        					row.createCell(count1).setCellValue(str2);
	        					continue;
	        				}
	        				for(int s=0;s<list.size();s++) {
	        					str = str+list.get(s);
	        					if(s!=list.size()-1) {
	        						str = str+" , ";
	        					}
	        				}
	        				row.createCell(count1).setCellValue(str);
	        			}
	        		}
	        	}
	        }
		}
	}

	//职业紧张压力问卷
	public void getOSI(Sheet sheet,Map<String,Object> mapIn,String time,Workbook wb) throws Exception {
			//查询患者 + 记录
			Map<String,Object> paramMap = new HashMap<String,Object>();
			List<String> queueList = new ArrayList<String>();
			String queueId1 ="12lczsqueue001";//12SMJD000000001  //12chyyjlqueue001
			String tenantId ="lczsta001";//lczsta001
			//String deptId="chyyjldept001";
			//String shequ="18862163677";
			queueList.add(queueId1);
			paramMap.put("examinationPaperName","OSI");
			paramMap.put("queueIdIn",queueList);
			paramMap.put("tenantId",tenantId);
			paramMap.put("beginTime",time+"-01 00:00:00");
			paramMap.put("endTime",time+"-31 23:59:59");
			List<Map<String,Object>> records = followEvaluationDao.selectEvaluationResultAll(paramMap);

			//查询当前抑郁问卷信息
			Map<String, Object> paramMap1 = new HashMap<String, Object>();
			paramMap1.put("field",Constants.FOLLOW_EVALUATION_PREGNANT_KEY);
			paramMap1.put("key",Constants.FOLLOW_EVALUATION_PREGNANT_OSI);
			FuAssessMentPosition position = followEvaluationDao.selectAssessMentPosition(paramMap1);
			paramMap1 = ToolUtils.typeCast(JSON.parse(position.getValue()));
			JSONArray json = (JSONArray)paramMap1.get("quetions");
			//查询患者建档资料
			if(!CollectionUtils.isEmpty(records)){
				for(int i =0 ;i<records.size();i++){
//						String userId = records.get(i).get("userId").toString();
					String ptSchemeId= records.get(i).get("ptSchemeId").toString();
					String queueId = records.get(i).get("queueId").toString();
					String deptId = records.get(i).get("deptId").toString();
			        paramMap.clear();
			        paramMap.put("seqNo", Constants.TASK_SEQ_FOR_INIT);
			        paramMap.put("ptSchemeId",ptSchemeId);
					// 查询taskid
					List<PatientTask> taskList = patientTaskDao.select(paramMap);
					String taskId ="";
					if (!CollectionUtils.isEmpty(taskList)) {
						taskId = taskList.get(0).getId();
					}

					paramMap.clear();
					paramMap.put("tenantId", tenantId);
					paramMap.put("groupType", Constants.TENANT_GROUP_TYPE_FOR_MULCENTER);
					paramMap.put("rootGroupId", deptId);
			        if (null == queueId || "".equals(queueId)) {
			            throw (new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_INPUT_DATA_VERIFY_ERROR, "入参节点错误，未传入队列id或值为空！"));
			        }
			        paramMap.put("taskId", taskId);
			        paramMap.put("queueId", queueId);
			        Map<String, Object> retMap = patientSerivce.qryPatientContentList(paramMap);
//							        logger.info(retMap.get("values").toString());
			        JSONObject questiones =JSONObject.parseObject(JSON.toJSONString(retMap.get("values")));
			        String Pub1100002 = questiones.getString("Pub1100002");
			        String Pub1100004 = questiones.getString("Pub1100004");
			        String Pub1100005 = questiones.getString("Pub1100005");

			        records.get(i).put("Pub1100002",Pub1100002);
			        records.get(i).put("Pub1100004",Pub1100004);
			        records.get(i).put("Pub1100005",Pub1100005);

			        if(null == records.get(i).get("testTime")){
				        records.get(i).put("testTime",records.get(i).get("createTime").toString().substring(0,10));
			        }else{
				        records.get(i).put("testTime",records.get(i).get("testTime").toString());
			        }
				}
			}

			//创建HSSFRow对象
			Row row = sheet.createRow(0);
			//创建HSSFCell对象
			Cell cell=row.createCell(0);
			//设置单元格的值
			cell.setCellValue("用户号码");
			cell = row.createCell(1);
			cell.setCellValue("姓名");
			cell = row.createCell(2);
			cell.setCellValue("出生日期");
			cell = row.createCell(3);
			cell.setCellValue("预产期");
			cell = row.createCell(4);
			cell.setCellValue("∑");
			cell = row.createCell(5);
			cell.setCellValue("#1");
			cell = row.createCell(6);
			cell.setCellValue("#2");
			cell = row.createCell(7);
			cell.setCellValue("#3");
			cell = row.createCell(8);
			cell.setCellValue("#4");
			cell = row.createCell(9);
			cell.setCellValue("#5");
			cell = row.createCell(10);
			cell.setCellValue("#6");
			cell = row.createCell(11);
			cell.setCellValue("#7");
			int count =12;//列数
			List<Object> list1 = null;
			List<Object> list2 = new ArrayList<Object>();
			for(int i=0;i<json.size();i++) {
				JSONObject josn2 = JSONObject.parseObject(json.get(i).toString());
				JSONArray josn3 = josn2.getJSONArray("questions");
				for(int j=0;j<josn3.size();j++) {
					JSONArray josn4 = josn3.getJSONObject(j).getJSONArray("list");
					//是否list
					if(josn4!=null&&josn4.size()>0) {
						for(int s =0;s<josn4.size();s++) {
							Map<String,Object> map = new HashMap<String,Object>();
							//取出问题题目
							Object obj = josn4.getJSONObject(s).get("description");
							map.put("id", josn4.getJSONObject(s).get("id"));
							map.put("option", josn4.getJSONObject(s).get("option"));
							if(obj==null) {
								continue;
							}else {
								if(obj instanceof List) {
									list1 = ToolUtils.typeCast(obj);
									map.put("count", count);
									cell = row.createCell(count);
									String ut ="";
									for(Object obj2 :list1) {
										if(obj2.equals("text")||obj2.equals("text-num")||obj2.equals("text-boxes")||obj2.equals("text-time")||obj2.equals("text-date")) {
											ut = ut+"_____";
										}else {
											ut = ut+obj2;
										}
									}
									cell.setCellValue(ut);
									count++;
								}else {
									cell = row.createCell(count);
									map.put("count", count);
									cell.setCellValue((String)obj);
									count++;
								}

							}
							list2.add(map);
						}
					}else {
						Map<String,Object> map = new HashMap<String,Object>();
						//取出问题题目
						Object obj = josn3.getJSONObject(j).get("description");
						map.put("id", josn3.getJSONObject(j).get("id"));
						map.put("option", josn3.getJSONObject(j).get("option"));
						if(obj==null) {
							continue;
						}else {
							if(obj instanceof List) {
								list1 = ToolUtils.typeCast(obj);
								map.put("count", count);
								cell = row.createCell(count);
								String ut ="";
								for(Object obj2 :list1) {
									if(obj2.equals("text")||obj2.equals("text-num")||obj2.equals("text-boxes")||obj2.equals("text-time")||obj2.equals("text-date")) {
										ut = ut+"_____";
									}else {
										ut = ut+obj2;
									}
								}
								cell.setCellValue(ut);
								count++;
							}else {
								cell = row.createCell(count);
								map.put("count", count);
								cell.setCellValue((String)obj);
								count++;
							}
						}
						list2.add(map);
					}
				}
			}
			CellStyle style = wb.createCellStyle();
			style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式

			for (int i = 0; i < records.size(); i++)
			{
				row = sheet.createRow((int) i + 1);
				Map<String,Object> map = records.get(i);
				// 第四步，创建单元格，并设置值
				row.createCell(0).setCellValue(map.get("phoneNum").toString());
				row.createCell(1).setCellValue(map.get("userName").toString());
				try {
					row.createCell(2).setCellValue(map.get("birthday").toString());
				} catch (Exception e) {
					row.createCell(2).setCellValue((String)map.get("birthday"));
				}
				row.createCell(3).setCellValue((String)map.get("Pub1100005"));
			    String score = (String)records.get(i).get("score");
		        JSONObject json3 = JSONObject.parseObject(score);
		        row.createCell(4).setCellValue(json3.getIntValue("total"));
				row.createCell(5).setCellValue(json3.getIntValue("total1"));
				row.createCell(6).setCellValue(json3.getIntValue("total2"));
				row.createCell(7).setCellValue(json3.getIntValue("total3"));
				row.createCell(8).setCellValue(json3.getIntValue("total4"));
				row.createCell(9).setCellValue(json3.getIntValue("total5"));
				row.createCell(10).setCellValue(json3.getIntValue("total6"));
				row.createCell(11).setCellValue(json3.getIntValue("total7"));
				String result = (String)records.get(i).get("result");
		        JSONObject json4 = JSONObject.parseObject(result);
		        paramMap1 = ToolUtils.typeCast(JSON.parse(json4.getString("ques")));
		        for (String in : paramMap1.keySet()) {
		        	 //map.keySet()返回的是所有key的值
		        	List<String> list = new ArrayList<String>();
		        	String str2="";
		        	try {
		        		list  = ToolUtils.typeCast(paramMap1.get(in));
					} catch (Exception e) {
						str2  = (String)paramMap1.get(in);
					}
		        	for(int j1 = 0;j1<list2.size();j1++) {
		        		Map<String,Object> map1 =  ToolUtils.typeCast(list2.get(j1));
		        		String str ="";
		        		if(in.equals(map1.get("id"))) {
		        			if(map1.get("option")!=null&&map1.get("option")!="") {
		        				JSONObject json5 = ToolUtils.typeCast(map1.get("option"));
		        				List<String> list3 = ToolUtils.typeCast(paramMap1.get(in));
		        				str = json5.getString(list3.get(0));
		        				int count1 = (int) map1.get("count");
		        				row.createCell(count1).setCellValue(str);
		        			}else {
		        				int count1 = (int) map1.get("count");
		        				if(!StringUtils.isBlank(str2)) {
		        					row.createCell(count1).setCellValue(str2);
		        					continue;
		        				}
		        				for(int s=0;s<list.size();s++) {
		        					str = str+list.get(s);
		        					if(s!=list.size()-1) {
		        						str = str+" , ";
		        					}
		        				}
		        				row.createCell(count1).setCellValue(str);
		        			}
		        		}
		        	}
		        }
			}
		}


	//生活事件量表
	public void getGLE(Sheet sheet,Map<String,Object> mapIn,String time,Workbook wb) throws Exception {
		//查询患者 + 记录
		Map<String,Object> paramMap = new HashMap<String,Object>();
		List<String> queueList = new ArrayList<String>();
		String queueId1 ="12lczsqueue001";//12SMJD000000001  //12chyyjlqueue001
		String tenantId ="lczsta001";//lczsta001
		//String deptId="chyyjldept001";
		//String shequ="18862163677";
		queueList.add(queueId1);
		paramMap.put("examinationPaperName","GLE");
		paramMap.put("queueIdIn",queueList);
		paramMap.put("tenantId",tenantId);
		paramMap.put("beginTime",time+"-01 00:00:00");
		paramMap.put("endTime",time+"-31 23:59:59");
		List<Map<String,Object>> records = followEvaluationDao.selectEvaluationResultAll(paramMap);

		//查询当前抑郁问卷信息
		Map<String, Object> paramMap1 = new HashMap<String, Object>();
		paramMap1.put("field",Constants.FOLLOW_EVALUATION_PREGNANT_KEY);
		paramMap1.put("key",Constants.FOLLOW_EVALUATION_PREGNANT_GLE);
		FuAssessMentPosition position = followEvaluationDao.selectAssessMentPosition(paramMap1);
		paramMap1 = ToolUtils.typeCast(JSON.parse(position.getValue()));
		//查询患者建档资料
		if(!CollectionUtils.isEmpty(records)){
			for(int i =0 ;i<records.size();i++){
//					String userId = records.get(i).get("userId").toString();
				String ptSchemeId= records.get(i).get("ptSchemeId").toString();
				String queueId = records.get(i).get("queueId").toString();
				String deptId = records.get(i).get("deptId").toString();
		        paramMap.clear();
		        paramMap.put("seqNo", Constants.TASK_SEQ_FOR_INIT);
		        paramMap.put("ptSchemeId",ptSchemeId);
				// 查询taskid
				List<PatientTask> taskList = patientTaskDao.select(paramMap);
				String taskId ="";
				if (!CollectionUtils.isEmpty(taskList)) {
					taskId = taskList.get(0).getId();
				}

				paramMap.clear();
				paramMap.put("tenantId", tenantId);
				paramMap.put("groupType", Constants.TENANT_GROUP_TYPE_FOR_MULCENTER);
				paramMap.put("rootGroupId", deptId);
		        if (null == queueId || "".equals(queueId)) {
		            throw (new AppException(ErrorCode.FOLLOWUP_EXCEPTION_TYPE_INPUT_DATA_VERIFY_ERROR, "入参节点错误，未传入队列id或值为空！"));
		        }
		        paramMap.put("taskId", taskId);
		        paramMap.put("queueId", queueId);
		        Map<String, Object> retMap = patientSerivce.qryPatientContentList(paramMap);
//						        logger.info(retMap.get("values").toString());
		        JSONObject questiones =JSONObject.parseObject(JSON.toJSONString(retMap.get("values")));
		        String Pub1100002 = questiones.getString("Pub1100002");
		        String Pub1100004 = questiones.getString("Pub1100004");
		        String Pub1100005 = questiones.getString("Pub1100005");

		        records.get(i).put("Pub1100002",Pub1100002);
		        records.get(i).put("Pub1100004",Pub1100004);
		        records.get(i).put("Pub1100005",Pub1100005);

		        if(null == records.get(i).get("testTime")){
			        records.get(i).put("testTime",records.get(i).get("createTime").toString().substring(0,10));
		        }else{
			        records.get(i).put("testTime",records.get(i).get("testTime").toString());
		        }
			}
		}

		//创建HSSFRow对象
		Row row = sheet.createRow(0);
		//创建HSSFCell对象
		Cell cell=row.createCell(0);
		//设置单元格的值
		cell.setCellValue("用户号码");
		cell = row.createCell(1);
		cell.setCellValue("姓名");
		cell = row.createCell(2);
		cell.setCellValue("出生日期");
		cell = row.createCell(3);
		cell.setCellValue("预产期");
		int count =4;//列数
		List<Object> list1 = null;
		List<Object> list2 = new ArrayList<Object>();
		for(Object value : paramMap1.values()) {
			JSONArray josn2 = JSONArray.parseArray(value.toString());
			for(int j=0;j<josn2.size();j++) {
				JSONArray josn4 = josn2.getJSONObject(j).getJSONArray("list");
				//是否list
				if(josn4!=null&&josn4.size()>0) {
					for(int s =0;s<josn4.size();s++) {
						Map<String,Object> map = new HashMap<String,Object>();
						//取出问题题目
						Object obj = josn4.getJSONObject(s).get("description");
						try {
							map.put("id", josn4.getJSONObject(s).get("id").toString().replace(".", "-"));
						} catch (Exception e) {
							map.put("id", josn4.getJSONObject(s).get("id"));
						}
						map.put("option", josn4.getJSONObject(s).get("option"));
						if(obj==null) {
							continue;
						}else {
							if(obj instanceof List) {
								list1 = ToolUtils.typeCast(obj);
								map.put("count", count);
								cell = row.createCell(count);
								String ut ="";
								for(Object obj2 :list1) {
									if(obj2.equals("text")||obj2.equals("text-num")||obj2.equals("text-boxes")||obj2.equals("text-time")||obj2.equals("text-date")) {
										ut = ut+"_____";
									}else {
										ut = ut+obj2;
									}
								}
								cell.setCellValue(ut);
								count++;
							}else {
								cell = row.createCell(count);
								map.put("count", count);
								cell.setCellValue((String)obj);
								count++;
							}

						}
						list2.add(map);
					}
				}else {
					Map<String,Object> map = new HashMap<String,Object>();
					//取出问题题目
					Object obj = josn2.getJSONObject(j).get("description");
					map.put("id", josn2.getJSONObject(j).get("id"));
					map.put("option", josn2.getJSONObject(j).get("option"));
					if(obj==null) {
						continue;
					}else {
						if(obj instanceof List) {
							list1 = ToolUtils.typeCast(obj);
							map.put("count", count);
							cell = row.createCell(count);
							String ut ="";
							for(Object obj2 :list1) {
								if(obj2.equals("text")||obj2.equals("text-num")||obj2.equals("text-boxes")||obj2.equals("text-time")||obj2.equals("text-date")) {
									ut = ut+"_____";
								}else {
									ut = ut+obj2;
								}
							}
							cell.setCellValue(ut);
							count++;
						}else {
							cell = row.createCell(count);
							map.put("count", count);
							cell.setCellValue((String)obj);
							count++;
						}
					}
					list2.add(map);
				}
			}
		}
		CellStyle style = wb.createCellStyle();
		style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式

		for (int i = 0; i < records.size(); i++)
		{
			row = sheet.createRow((int) i + 1);
			Map<String,Object> map = records.get(i);
			// 第四步，创建单元格，并设置值
			row.createCell(0).setCellValue(map.get("phoneNum").toString());
			row.createCell(1).setCellValue(map.get("userName").toString());
			try {
				row.createCell(2).setCellValue(map.get("birthday").toString());
			} catch (Exception e) {
				row.createCell(2).setCellValue((String)map.get("birthday"));
			}
			row.createCell(3).setCellValue((String)map.get("Pub1100005"));
			String result = (String)records.get(i).get("result");
	        JSONObject json4 = JSONObject.parseObject(result);
	        paramMap1 = ToolUtils.typeCast(JSON.parse(json4.getString("ques")));
	        for (String in : paramMap1.keySet()) {
	        	 //map.keySet()返回的是所有key的值
	        	List<String> list = new ArrayList<String>();
	        	String str2="";
	        	try {
	        		list  = ToolUtils.typeCast(paramMap1.get(in));
				} catch (Exception e) {
					str2  = (String)paramMap1.get(in);
				}
	        	for(int j1 = 0;j1<list2.size();j1++) {
	        		Map<String,Object> map1 =  ToolUtils.typeCast(list2.get(j1));
	        		String str ="";
	        		if(in.equals(map1.get("id"))) {
	        			if(map1.get("option")!=null&&map1.get("option")!="") {
	        				try {
	        					JSONObject json5 = ToolUtils.typeCast(map1.get("option"));
	        					List<String> list3 = ToolUtils.typeCast(paramMap1.get(in));
		        				str = json5.getString(list3.get(0));
							} catch (Exception e) {
								if("2-13-5".equals(in)){
									for(int s=0;s<list.size();s++) {
										String str1="";
										if(s==list.size()-1) {
											if("0".equals(list.get(list.size()-1))) {
												str1 = "成功";
												str= str+str1;
											}else {
												str1 = "失败";
												str= str+str1;
											}
										}else {
											str = str+list.get(s);
										}

			        					if(s!=list.size()-1) {
			        						str = str+" , ";
			        					}
			        				}
								}
							}
	        				int count1 = (int) map1.get("count");
	        				row.createCell(count1).setCellValue(str);
	        			}else {
	        				int count1 = (int) map1.get("count");
	        				if(!StringUtils.isBlank(str2)) {
	        					row.createCell(count1).setCellValue(str2);
	        					continue;
	        				}
	        				for(int s=0;s<list.size();s++) {
	        					str = str+list.get(s);
	        					if(s!=list.size()-1) {
	        						str = str+" , ";
	        					}
	        				}
	        				row.createCell(count1).setCellValue(str);
	        			}
	        		}
	        	}
	        }
		}

	}
	//基本数据

	@Override
	public List<Map<String, Object>> getURLToUpload (Map<String, Object> MapIn) throws Exception {
		List<Map<String, Object>> list = iUploadExcelDAO.selectOperationNote(MapIn);
		return list;

	}

	//查询当前段时间中导出的文件
	@Override
	public List<Map<String, Object>> gettenantIdforProject (Map<String, Object> MapIn) throws Exception {
     List<Map<String, Object>> retList = confCacheDAO.selectBsStaticParamByTenant(MapIn);
     return retList;

	}

	//查询导出记录
	@Override
	public Map<String, Object> getURLToUploadDate(Map<String, Object> mapIn) throws Exception {

		//查询当前导出数据总条数
		Map<String,Object> map = new HashMap<String,Object>();
		int total= 0;
		total = iUploadExcelDAO.selectOperationNoteCount(mapIn);
		List<Map<String, Object>> list = null;
		if (total>0) {
			list = iUploadExcelDAO.selectOperationNote(mapIn);
		}
		map.put("rows", list);
		map.put("total", total);
		return map;
	}



}

